My ListView is raising events that don't exist - asp.net

So I have a listview:
<asp:listview runat="server" ID="listview_search" itemPlaceholderID="itemListing" DataSourceID="ds_search">
<LayoutTemplate>
<div id="sort" runat="server">
<asp:LinkButton runat="server" id="sortByPrice" CommandName="sort" CommandArgument="price" >Sort by price</asp:LinkButton>
</div>
<div runat="server" id="itemListing"></div>
</LayoutTemplate>
<ItemTemplate>
<div class="container profilelistings">
<div class="row carousel-row">
<div class="col-xs-8 col-xs-offset-2 slide-row" style="min-height: 100px;">
<div id="carousel-1" class="carousel slide slide-carousel">
<div class="carousel-inner">
<div class="item active">
<asp:Image id="img_car" imageurl='<%# "images/" + Eval("ownerID") + "/" + Eval("photo1") %>' runat="server"></asp:Image>
</div>
</div>
</div>
<div class="slide-content">
<h5><%# Eval("make").ToString() + " " + Eval("model") + " (" + Eval("type") + ") " %></h5>
<h5><span class="price"><%# "£ " + Eval("price") %></span></h5>
</div>
<div class="slide-footer">
<span class="pull-right buttons">
<button class="btn btn-sm btn-default"><i class="glyphicon glyphicon-eye-open"></i> View more info </button>
</span>
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:listview>
When I click the sortByPrice LinkButton it gives an error "The ListView 'listview_search' raised event Sorting which wasn't handled." When the event does not exist in the ListView itself nor in the code.
Does anyone understand why it is doing this?

Related

ModalPopupExtender does not show in aspx

i try to design a popup window in my aspx page. The problem is the page is reloaded and the popup not shown!
here is the code
aspx
<asp:ScriptManager ID="ScriptManager2" runat="server"></asp:ScriptManager>
<asp:Label ID="popuplbl" runat="server"></asp:Label>
<cc1:ModalPopupExtender ID="mpe" PopupControlID="panel1" TargetControlID="popuplbl" CancelControlID="cancelbtn" runat="server"></cc1:ModalPopupExtender>
<asp:Panel ID="panet1" class="modal fade in" runat="server">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" aria-hidden="true" type="button" data-dismiss="modal"></button>
<h4 class="modal-title">New Study Design</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<h4>Some Input</h4>
<p><input class="col-md-12 form-control" type="text"> </p>
<p><input class="col-md-12 form-control" type="text"> </p>
</div>
</div>
</div>
<div class="modal-footer">
<button id="cancelbtn" class="btn default" type="button" data-dismiss="modal">Cancel</button>
<button class="btn blue" type="button">Add</button>
</div>
</div>
</div>
</asp:Panel>
<button runat="server" id="AddNew_StudyDesign" class="btn sbold green" title="Add New Study Design" style="width:200px" onserverclick="AddNew_StudyDesign_Click" >
Add New Study Design <i class="fa fa-plus"></i>
</button>
c#
protected void AddNew_StudyDesign_Click(object sender, System.EventArgs e)
{
mpe.Show();
}
I try using "ToolkitScriptManager" but it is not known!
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<cc1:ToolkitScriptManager ID="ScriptManager1" runat="server" />
I can see one issue,
Replace PopupControlID attribute in ModalPopupExtender ,
PopupControlID="panel1"
To
PopupControlID="panet1"
Panel ID is panet1, not panel1.
Additionally, Panel should have display style none (style="display:none;"), but you can keep as per your requirements.

How to apply dynamic class in repeater?

I'm trying to create a repeater which contains elements with a dynamic class, as well as dynamic background color, and icons (which is put at run-time).
I have a repeater
<asp:Repeater ID="repdashboard" runat="server">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<div class="col-lg-3 col-md-6">
<div if("<%#Eval("id") %>"= 1 ? " class=panel-primary )>
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-comments fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge">26</div>
<div>'<%#Eval("Tag") %>'!</div>
</div>
</div>
</div>
<a href="#">
<div class="panel-footer" style="color: #337ab7;">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
I want to apply class on behalf of dynamic value in div
<div if("<%#Eval("id") %>"= 1 ? " class=panel-primary )>
when
`<%#Eval("id") %> = 1`
then apply class= panel panel-primary
and when
<%#Eval("id") %> = 2 then apply class=panel panel-green
You cannot just write an if somewhere in the html and expect it to work. You need a code block.
<div class="<%# Convert.ToInt32(Eval("id")) == 1 ? "panel panel-primary" : "panel panel-green" %>">
If you want a lot more evaluations to generate a class, I would recommend a method in code behind.
public string AddClass(int id)
{
if (id == 1)
return "panel panel-primary";
else if (id == 2)
return "panel panel-green";
else
return "panel other";
}
And then in the Repeater
<div class="<%# AddClass(Convert.ToInt32(Eval("id"))) %>">

Url Routing Asp.net

I have a blog page where blogs are fetched from database to my webpage.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" GridLines="None">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div class="blog_post">
<div class="col-lg-3 col-md-3 col-sm-3">
<div class="">
<img src='<%# Eval("photo")%>' alt="Couple blog image" width="205px" height="150px" />
</div>
</div>
<div class="col-lg-9 col-md-9 col-sm-9">
<p class="posting_date"><%# Eval("date","{0:MMMM dd,yyyy}")%></p>
<h3><a href='ReadBlog/<%# Eval("title").ToString()%>'><%# Eval("title")%></a></h3>
<%#Eval("title") %>
<p class="blog_text">
<%# Eval("sdesc")%>
<p class="blog_text">
<a class="btn btn-danger" style="color:wheat" href='read_blog.aspx?id=<%# Eval("title")%>'>Read Post</a>
</p>
</p>
</br></br>
<hr/>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
on my Read_blog.aspx.cs page I have used...
if (!IsPostBack)
{
string myquery = Page.RouteData.Values["id"].ToString();
cls.gridbind(GridView1, "select * from tbl_blog_master where title='" + Request.QueryString["id"].ToString() + "' order by date desc");
}
I want to get the url like this
localhost/readblog/my-first-blog
help me please i am new to asp.net and have to learn a lot...
This is my first time on stackoverflow so sorry for my english..

Need to create a report using report viewer

I need to create a report using Report viewer. unfortunately, I haven't worked on Report viewer before. My SQL query accepts 3 parameters to fetch the data from SQL server. Query would be:
Select col1,col2,col3 from table1 where area='ddlselectedarea' and start_date='01-01-2016' and end_date='31-01-2016'
My UI would be:
<section id="content" class="has-btn-bar-btm-fixed"><!-- content -->
<form runat="server" class="form-horizontal custom-form row">
<div class="cost-transfer-block"><!-- cost-transfer-block -->
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-lg-10">
<h2>Dump by item</h2>
<div class="col-md-6">
<div class="form-group">
<asp:label runat="server" Text="From Site" ID="lblFromSite" class="control-label col-sm-3 col-md-3 col-lg-3" ></asp:label>
<div class="col-sm-9">
<div class="input-group">
<select class="form-control">
<asp:DropDownList ID="DdlFromsite" runat="server" ></asp:DropDownList>
</select>
<span class="input-group-addon"> </span>
</div>
</div>
</div>
</div>
<div class="col-md-6 cst-brd-left">
<div class="form-group">
<asp:label runat="server" Text="From Date" ID="lblFromDate" class="control-label col-sm-3 col-md-3 col-lg-3" ></asp:label>
<div class="col-sm-9 transferdate">
<div class="input-group date">
<input type="date" class="form-control" id="" placeholder="Select Date" >
<span class="input-group-addon"><img src="images/icon-add-on-2-date.png" alt="" /></span>
</div>
</div>
</div>
<div class="form-group">
<asp:label runat="server" Text="To Date" ID="lblToDate" class="control-label col-sm-3 col-md-3 col-lg-3" >To Date</asp:label>
<div class="col-sm-9 transferdate">
<div class="input-group date">
<input type="date" class="form-control" id="" placeholder="Select Date" >
<span class="input-group-addon"><img src="images/icon-add-on-2-date.png" alt="" /></span>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-4 col-lg-2">
</div>
</div>
</div>
</div>
<!-- /cost-transfer-block -->
<%--<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<rsweb:ReportViewer ID="ReportViewer1" runat="server"></rsweb:ReportViewer>--%>
<div class="gray-btn-row clearfix">
<div class="btns-group">
<asp:button runat="server" Text="Enter" ID="btnEnter" class="btn btn-dark-blue"></asp:button>
</div>
</div>
</form>
</section>
Please guide me in designing a report using the reportviewer
The report viewer is a totally new component which needed to be designed using Report viewer or report viewer wizard. You can add any of them from the Add new items pane and bind a data table to that component.
I hope this helps others

Creating asp buttons with different text depending on value of a field in repeater

For my .NET project I have to output data from an access file to a repeater and generate buttons next to each item in order for customers to rent the items displayed. I've been trying to find a way to generate buttons with different text depending on the value of a field in the repeater. More specifically, I'd like the button to say "rent for £3.50" if price_band is A and "rent for £2.50" if price_band is B. Up to now I've tried several approaches to no avail. Any help would be appreciated, Thanks!
<ItemTemplate>
<div class="list-group-item active">
<div class="row">
<div class="col-md-3">
<p class="list-group-item-text"><img src="<%# Eval("image")%>" /></p>
</div>
<div class="col-md-4">
<h4 class="list-group-item-heading"><%# Eval("title")%></h4>
<p class="list-group-item-text"><strong>Director: </strong><%# Eval("director")%></p>
<p class="list-group-item-text"><strong>Cast: </strong><%# Eval("cast")%></p>
<p class="list-group-item-text"><strong>Genre: </strong><%# Eval("genre")%></p>
<p class="list-group-item-text"><strong>Year Released: </strong><%# Eval("year_released")%></p>
<p class="list-group-item-text"><strong>Rating: </strong><%# Eval("rating")%></p>
<p class="list-group-item-text"><strong>IMDB Score: </strong><%# Eval("imdb_rating")%></p>
<p class="list-group-item-text"><strong>Price Band: </strong><%# Eval("price_band")%></p>
</div>
<div class="col-md-1">
<% if (Session["customer"] != null) { %>
<%if("price_band" == "A"){%>
<asp:Button ID="btnRent" runat="server" Text="Rent for £3.50"/>
<% } %>
<%else if("price_band" == "B"){%>
<asp:Button ID="btnRent1" runat="server" Text="Rent for £2.50"/>
<% } %>
<% }
else { %>
<asp:Button ID="btnLoginWarning" runat="server" Text="Must be logged in to rent"/>
<%} %>
</div>
</div>
</div>
</ItemTemplate>

Resources