Passing Eval Through Command Argument in Listview - asp.net

I have a link button that I am trying to pass a parameter through into the OnClick event handler. To do this I am using the CommandArgument field.
I have this link button within a listview so I am retireving the data using Eval, so I want to pass that value into the CommandArgument as such:
<asp:LinkButton id="BTN_ApproveTicket" runat="server" CommandArgument="<%#Eval("TicketNum").ToString()%>" OnClick="BTN_ApproveTicket_Click">
</asp:LinkButton>
I am doing this exact think with some table elements in my page, but this one is not working.
The error that I am getting is it is taking the <%#Eval("TicketNum").ToString() as a literal, so I am getting a server tag is not well formatted error. Any ideas on how to fix this would be greatly appreciated.
This is the AlternatingItemTemplate that is in question:
<AlternatingItemTemplate>
<td style="<%#setTicketClass(Eval("TicketNum").ToString(), Eval("UnitID").ToString(), Eval("TicketDate").ToString())%>" >
<asp:LinkButton id="BTN_ApproveTicket" runat="server" CommandArgument='<%#Eval("TicketNum").ToString()%>' OnClick="BTN_ApproveTicket_Click">
<i class="fa fa-check-square-o" style="<%#setCheckBoxClass(Eval("Approved").ToString())%>" ></i>
</asp:LinkButton>
<br />
<br />
JobID:
<asp:Label ID="JobIDLabel" runat="server" Text='<%# Eval("JobID") %>' />
<br />
Ticket #:
<asp:Label ID="TicketNumLabel" runat="server" Text='<%# Eval("TicketNum") %>' />
<br />
Unit:
<asp:Label ID="UnitIDLabel" runat="server" Text='<%# Eval("UnitID") %>' />
<br />
Total Ticket Hours:
<asp:Label ID="TicketHoursLabel" runat="server" Text='<%# Eval("TicketHours") %>' />
<br />
Total Product:
<asp:Label ID="TicketProductLabel" runat="server" Text='<%# Eval("TicketProduct") %>' />
<br />
Ticket Date:
<asp:Label ID="TicketDateLabel" runat="server" Text='<%# Eval("TicketDate", "{0:MMM dd yyyy}") %>' />
<br />
Charge To Customer:
<asp:Label ID="ChargeToCustomerLabel" runat="server" Text='<%# Eval("ChargeToCustomer") %>' />
<br />
Received From Customer:
<asp:Label ID="RecievedToCuLabel" runat="server" Text='<%# Eval("RecievedToCu") %>' />
<br />
Deliver To Customer:
<asp:Label ID="DeliverTocu" runat="server" Text='<%# Eval("DeliverToCu") %>' />
<br />
Charged To LSD:
<asp:Label ID="LBL_ChargedToLSD" runat="server" Text='<%# Eval("ChargedToLSD") %>' />
<br />
Received From LSD:
<asp:Label ID="RecievedFromLSDLabel" runat="server" Text='<%# Eval("RecievedFromLSD") %>' />
<br />
Delivered To LSD:
<asp:Label ID="DeliveredToLSDLabel" runat="server" Text='<%# Eval("DeliveredToLSD") %>' />
<br />
Subtotal:
<asp:Label ID="SubtotalLabel" runat="server" Text='<%# Eval("Subtotal", "{0:C}") %>' Font-Bold="True" />
<br />
GST:
<asp:Label ID="GSTLabel" runat="server" Text='<%# Eval("GST", "{0:P}") %>' Font-Bold="True" />
<br />
Total:
<asp:Label ID="TotalLabel" runat="server" Text='<%# Eval("Total", "{0:C}") %>' Font-Bold="True" />
<br />
Job Notes:
<asp:Label ID="PreJobNotesLabel" runat="server" Text='<%# Eval("PreJobNotes") %>' />
<br />
Job Description:
<asp:Label ID="JobDescLabel" runat="server" Text='<%# Eval("JobDesc") %>' />
<br />
Time Created:
<asp:Label ID="TimeCreatedLabel" runat="server" Text='<%# Eval("TimeCreated", "{0: MMM-dd-yyyy HH:mm}") %>' />
<br />
Created By:
<asp:Label ID="CreatedByLabel" runat="server" Text='<%# Eval("CreatedBy") %>' />
<br />
<asp:LinkButton class="btn-inverse" id="EditButton" runat="server" CommandName="Edit" Text="Edit" Enabled='<%# checkButtonEnabled() %>' style="padding: 2px 8px; text-decoration: none; border: solid 1px;" >
<span class="glyphicon glyphicon-edit"></span> Edit
</asp:LinkButton>
<asp:LinkButton class="btn-inverse" id="DeleteButton" runat="server" CommandName="Delete" Text="Delete" onclientclick="return DeleteItem()" Enabled='<%# checkButtonEnabled() %>' style="padding: 2px 8px; text-decoration: none; border: solid 1px;" >
<span class="glyphicon glyphicon-trash"></span> Delete
</asp:LinkButton>
<asp:LinkButton class="btn-inverse" id="SelectButton" runat="server" CommandName="Select" Text="Show Product" style="padding: 2px 8px; text-decoration: none; border: solid 1px; white-space: nowrap;" >
<span class="glyphicon glyphicon-menu-down"></span> Show Product
</asp:LinkButton>
</td>
</AlternatingItemTemplate>

It might have to do with quotes - you are using double quotes everywhere, which may confuse parser. Try replacing outer ones with single quote:
CommandArgument='<%#Eval("TicketNum").ToString()%>'

Related

ASP.NET Listview not saving edit

I am trying to use a listview to display and update marks.
The data displays without any issues, however when I click edit, then insert data and try to save the changes, the listview fails to do so and loads in the same state is was prior to the update attempt. Any ideas what is going on?
<asp:SqlDataSource ID="StudentResultsDS" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
SelectCommand="SELECT Module_Info.ModuleTitle, Module_Info.UserID, Module_Info.ModuleCode, Modules.ModuleMarks, Modules.MarkID, Modules.ExamMark, Modules.AssignmentMark, Users.SNumber, Lecturer_Records.UserID AS Expr1 FROM Module_Info INNER JOIN Modules ON Module_Info.ModuleID = Modules.ModuleID INNER JOIN Users ON Modules.UserID = Users.UserID INNER JOIN Lecturer_Records ON Users.UserID = Lecturer_Records.UserID WHERE (Lecturer_Records.UserID = #UserID)" UpdateCommand="UPDATE [Modules] SET [ModuleMarks]=#ModuleMarks WHERE [MarkID]=#MarkID" >
<UpdateParameters>
<asp:FormParameter Name="ModuleMarks" Type="String" />
<asp:FormParameter Name="MarkID" Type="String" />
</UpdateParameters>
<SelectParameters>
<asp:SessionParameter Name="UserID" SessionField="grabUserID" />
</SelectParameters>
</asp:SqlDataSource>
<!-- list view to display results-->
<header class="jumbotron hero-spacer">
<asp:ListView runat="server" ID="listviewid" DataSourceID="StudentResultsDS" DataKeyNames="ModuleMarks">
<AlternatingItemTemplate>
<span style="">ModuleTitle:
<asp:Label ID="ModuleTitleLabel" runat="server" Text='<%# Eval("ModuleTitle") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
ModuleCode:
<asp:Label ID="ModuleCodeLabel" runat="server" Text='<%# Eval("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:Label ID="ModuleMarksLabel" runat="server" Text='<%# Eval("ModuleMarks") %>' />
<br />
MarkID:
<asp:Label ID="MarkIDLabel" runat="server" Text='<%# Eval("MarkID") %>' />
<br />
ExamMark:
<asp:Label ID="ExamMarkLabel" runat="server" Text='<%# Eval("ExamMark") %>' />
<br />
AssignmentMark:
<asp:Label ID="AssignmentMarkLabel" runat="server" Text='<%# Eval("AssignmentMark") %>' />
<br />
SNumber:
<asp:Label ID="SNumberLabel" runat="server" Text='<%# Eval("SNumber") %>' />
<br />
Expr1:
<asp:Label ID="Expr1Label" runat="server" Text='<%# Eval("Expr1") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
<br />
</span>
</AlternatingItemTemplate>
<EditItemTemplate>
<span style="">ModuleTitle:
<asp:TextBox ID="ModuleTitleTextBox" runat="server" Text='<%# Bind("ModuleTitle") %>' />
<br />
UserID:
<asp:TextBox ID="UserIDTextBox" runat="server" Text='<%# Bind("UserID") %>' />
<br />
ModuleCode:
<asp:TextBox ID="ModuleCodeTextBox" runat="server" Text='<%# Bind("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:TextBox ID="ModuleMarksTextBox" runat="server" Text='<%# Bind("ModuleMarks") %>' />
<br />
MarkID:
<asp:Label ID="MarkIDLabel1" runat="server" Text='<%# Eval("MarkID") %>' />
<br />
ExamMark:
<asp:TextBox ID="ExamMarkTextBox" runat="server" Text='<%# Bind("ExamMark") %>' />
<br />
AssignmentMark:
<asp:TextBox ID="AssignmentMarkTextBox" runat="server" Text='<%# Bind("AssignmentMark") %>' />
<br />
SNumber:
<asp:TextBox ID="SNumberTextBox" runat="server" Text='<%# Bind("SNumber") %>' />
<br />
Expr1:
<asp:TextBox ID="Expr1TextBox" runat="server" Text='<%# Bind("Expr1") %>' />
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
<br />
<br />
</span>
</EditItemTemplate>
<EmptyDataTemplate>
<span>No data was returned.</span>
</EmptyDataTemplate>
<InsertItemTemplate>
<span style="">ModuleTitle:
<asp:TextBox ID="ModuleTitleTextBox" runat="server" Text='<%# Bind("ModuleTitle") %>' />
<br />
UserID:
<asp:TextBox ID="UserIDTextBox" runat="server" Text='<%# Bind("UserID") %>' />
<br />
ModuleCode:
<asp:TextBox ID="ModuleCodeTextBox" runat="server" Text='<%# Bind("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:TextBox ID="ModuleMarksTextBox" runat="server" Text='<%# Bind("ModuleMarks") %>' />
<br />
ExamMark:
<asp:TextBox ID="ExamMarkTextBox" runat="server" Text='<%# Bind("ExamMark") %>' />
<br />
AssignmentMark:
<asp:TextBox ID="AssignmentMarkTextBox" runat="server" Text='<%# Bind("AssignmentMark") %>' />
<br />
SNumber:
<asp:TextBox ID="SNumberTextBox" runat="server" Text='<%# Bind("SNumber") %>' />
<br />
Expr1:
<asp:TextBox ID="Expr1TextBox" runat="server" Text='<%# Bind("Expr1") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
<br />
<br />
</span>
</InsertItemTemplate>
<ItemTemplate>
<span style="">ModuleTitle:
<asp:Label ID="ModuleTitleLabel" runat="server" Text='<%# Eval("ModuleTitle") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
ModuleCode:
<asp:Label ID="ModuleCodeLabel" runat="server" Text='<%# Eval("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:Label ID="ModuleMarksLabel" runat="server" Text='<%# Eval("ModuleMarks") %>' />
<br />
MarkID:
<asp:Label ID="MarkIDLabel" runat="server" Text='<%# Eval("MarkID") %>' />
<br />
ExamMark:
<asp:Label ID="ExamMarkLabel" runat="server" Text='<%# Eval("ExamMark") %>' />
<br />
AssignmentMark:
<asp:Label ID="AssignmentMarkLabel" runat="server" Text='<%# Eval("AssignmentMark") %>' />
<br />
SNumber:
<asp:Label ID="SNumberLabel" runat="server" Text='<%# Eval("SNumber") %>' />
<br />
Expr1:
<asp:Label ID="Expr1Label" runat="server" Text='<%# Eval("Expr1") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
<br />
</span>
</ItemTemplate>
<LayoutTemplate>
<div id="itemPlaceholderContainer" runat="server" style="">
<span runat="server" id="itemPlaceholder" />
</div>
<div style="">
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<span style="">ModuleTitle:
<asp:Label ID="ModuleTitleLabel" runat="server" Text='<%# Eval("ModuleTitle") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
ModuleCode:
<asp:Label ID="ModuleCodeLabel" runat="server" Text='<%# Eval("ModuleCode") %>' />
<br />
ModuleMarks:
<asp:Label ID="ModuleMarksLabel" runat="server" Text='<%# Eval("ModuleMarks") %>' />
<br />
MarkID:
<asp:Label ID="MarkIDLabel" runat="server" Text='<%# Eval("MarkID") %>' />
<br />
ExamMark:
<asp:Label ID="ExamMarkLabel" runat="server" Text='<%# Eval("ExamMark") %>' />
<br />
AssignmentMark:
<asp:Label ID="AssignmentMarkLabel" runat="server" Text='<%# Eval("AssignmentMark") %>' />
<br />
SNumber:
<asp:Label ID="SNumberLabel" runat="server" Text='<%# Eval("SNumber") %>' />
<br />
Expr1:
<asp:Label ID="Expr1Label" runat="server" Text='<%# Eval("Expr1") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
<br />
</span>
</SelectedItemTemplate>
</asp:ListView>
Try changing it to a gridview which should allow the update to work. Try this code below:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="searchStudentResults" cssClass="table table-hover" AllowSorting="True" OnRowUpdated="GridView1_RowUpdated1" >
<Columns>
<asp:BoundField DataField="StudentNo" HeaderText="StudentNo" SortExpression="StudentNo" ReadOnly="true" />
<asp:BoundField DataField="ExamMark" HeaderText="Exam %" SortExpression="ExamMark" />
<asp:BoundField DataField="AssignmentMark" HeaderText="Assignment %" SortExpression="AssignmentMark" />
<asp:BoundField DataField="ModuleMarks" SortExpression="ModuleMarks" HeaderText="ModuleMarks" ReadOnly="true" DataFormatString="{0:0}" />
<asp:CommandField ShowEditButton="True" ButtonType="Button" EditText="Add Marks" ControlStyle-CssClass="btn btn-primary" ItemStyle-Width="100px" >
<ControlStyle CssClass="btn btn-primary"></ControlStyle>
<ItemStyle Width="100px"></ItemStyle>
</asp:CommandField>
<asp:BoundField DataField="MarkID" ControlStyle-CssClass="hidden" ItemStyle-CssClass="hidden" HeaderStyle-CssClass="hidden" >
<ControlStyle CssClass="hidden"></ControlStyle>
<HeaderStyle CssClass="hidden"></HeaderStyle>
<ItemStyle CssClass="hidden"></ItemStyle>
</asp:BoundField>
</Columns>
<EmptyDataTemplate>
No marks to enter
</EmptyDataTemplate>
</asp:GridView>

Why ImageButton Display Text SubmitQuery Runtime

i use imagebutton in datalist and set codeexpression :Eval("PictureUrl", "ProductImages\thumb_{0}") and runtime display submitquery.
<asp:DataList ID="DataList1" runat="server" DataKeyField="pid"
DataSourceID="SqlDataSource1">
<ItemTemplate>
pname:
<asp:Label ID="pnameLabel" runat="server" Text='<%# Eval("pname") %>' />
<br />
pprice:
<asp:Label ID="ppriceLabel" runat="server" Text='<%# Eval("pprice") %>' />
<br />
publisher:
<asp:Label ID="publisherLabel" runat="server" Text='<%# Eval("publisher") %>' />
<br />
writer:
<asp:Label ID="writerLabel" runat="server" Text='<%# Eval("writer") %>' />
<br />
<asp:ImageButton ID="ImageButton7" runat="server"
ImageUrl='<%# Eval("PictureUrl", "ProductImages\thumb_{0}") %>' />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:dbpath %>"
SelectCommand="SELECT [pname], [pprice], [PictureUrl], [gid], [storeid], [publisher], [writer], [pid] FROM [tblproduct]">
</asp:SqlDataSource>
output one record:
pname:
<span id="ContentPlaceHolder1_DataList1_pnameLabel_0">تکنیک عکاسی</span>
<br />
pprice:
<span id="ContentPlaceHolder1_DataList1_ppriceLabel_0">125000 </span>
<br />
publisher:
<span id="ContentPlaceHolder1_DataList1_publisherLabel_0">اسرار دانش</span>
<br />
writer:
<span id="ContentPlaceHolder1_DataList1_writerLabel_0">نصرالله کسرائیان</span>
<br />
<input type="image" name="ctl00$ContentPlaceHolder1$DataList1$ctl00$ImageButton7" id="ContentPlaceHolder1_DataList1_ImageButton7_0" src="ProductImages%09humb_~/image/tecnikakasi.jpg" />
You got the correct HTML rendered
<asp:ImageButton ID="ImageButton7" runat="server"
ImageUrl='<%# Eval("PictureUrl", "ProductImages\thumb_{0}") %>' />
will produce input tag with type=image
<input type="image" name="ctl00$ContentPlaceHolder1$DataList1$ctl00$ImageButton7" id="ContentPlaceHolder1_DataList1_ImageButton7_0" src="ProductImages%09humb_~/image/tecnikakasi.jpg" />
The problem is ProductImages%09humb_~/image/tecnikakasi.jpg not exists. It may be wrong.
Check the relative path rendered.
Try
ImageUrl='<%# Eval("PictureUrl", "~/ProductImages/thumb_{0}") %>'
It is displaying "SubmitQuery" because your image is not being loaded. If your writer alternate text, then alternate text will be displayed.
You can view source of the generated html and check the path of the image and try to correct it for resolving this problem.
ImageUrl='<%# Eval("PictureUrl", "{0}") %>'

How can i add a event handler to a customized button inside listview?

This is my markup
<%# Page Title="Daily Expenses" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Daily Expenses.aspx.cs" Inherits="Daily_Expenses" %>
function calendar_datechange() {
__doPostBack('txtCalendar', 'txtCalendar_TextChanged');
}
function Calculate_Difference() {
alert("Hello");
}
</script>
<asp:ToolkitScriptManager ID="AjaxScript" runat="server"></asp:ToolkitScriptManager>
<asp:TextBox ID="txtCalendar" runat="server"
ontextchanged="txtCalendar_TextChanged"></asp:TextBox>
<%--<asp:PopupControlExtender ID="txtCalendar_PopupControlExtender" runat="server"
DynamicServicePath="" Enabled="True" ExtenderControlID="" PopupControlID="Panel1"
TargetControlID="txtCalendar">
</asp:PopupControlExtender>
<asp:Panel ID="Panel1" runat="server">
<h2>Hello There</h2>
</asp:Panel>--%>
<asp:CalendarExtender ID="CalendarControl" runat="server" OnClientDateSelectionChanged="calendar_datechange" TargetControlID="txtCalendar" PopupButtonID="CalendarButton">
</asp:CalendarExtender>
<%--<ajaxToolkit:CalendarExtender ID="CalendarControl" runat="server" OnClientDateSelectionChanged="calendar_datechange" TargetControlID="txtCalendar" PopupButtonID="CalendarButton"></ajaxToolkit:CalendarExtender>--%>
<asp:Button ID="CalendarButton" runat="server" Text="Calendar" />
<br />
<br />
<br />
<asp:ListView ID="ListView1" runat="server" DataKeyNames="SNO"
DataSourceID="SqlDataSource1" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<li style="background-color: #FFF8DC;">SNO:
<asp:Label ID="SNOLabel" runat="server" Text='<%# Eval("SNO") %>' />
<br />
Taxinreal:
<asp:Label ID="TaxinrealLabel" runat="server" Text='<%# Eval("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:Label ID="TaxinpercentLabel" runat="server"
Text='<%# Eval("Taxinpercent") %>' />
<br />
Amount:
<asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
<br />
NetAmount:
<asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:Label ID="DateTakenPlaceLabel" runat="server"
Text='<%# Eval("DateTakenPlace") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="Differencebutton" runat="server" Text="Calculate Difference" OnClientClick="Calculate_Difference" />
</li>
</AlternatingItemTemplate>
<EditItemTemplate>
<li style="background-color: #008A8C;color: #FFFFFF;">SNO:
<asp:Label ID="SNOLabel1" runat="server" Text='<%# Eval("SNO") %>' />
<br />
Taxinreal:
<asp:TextBox ID="TaxinrealTextBox" runat="server"
Text='<%# Bind("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:TextBox ID="TaxinpercentTextBox" runat="server"
Text='<%# Bind("Taxinpercent") %>' />
<br />
Amount:
<asp:TextBox ID="AmountTextBox" runat="server" Text='<%# Bind("Amount") %>' />
<br />
NetAmount:
<asp:TextBox ID="NetAmountTextBox" runat="server"
Text='<%# Bind("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:TextBox ID="DateTakenPlaceTextBox" runat="server"
Text='<%# Bind("DateTakenPlace") %>' />
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
<asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
</li>
</EditItemTemplate>
<EmptyDataTemplate>
No data was returned.
</EmptyDataTemplate>
<InsertItemTemplate>
<li style="">Taxinreal:
<asp:TextBox ID="TaxinrealTextBox" runat="server"
Text='<%# Bind("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:TextBox ID="TaxinpercentTextBox" runat="server"
Text='<%# Bind("Taxinpercent") %>' />
<br />
Amount:
<asp:TextBox ID="AmountTextBox" runat="server" Text='<%# Bind("Amount") %>' />
<br />
NetAmount:
<asp:TextBox ID="NetAmountTextBox" runat="server"
Text='<%# Bind("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:TextBox ID="DateTakenPlaceTextBox" runat="server"
Text='<%# Bind("DateTakenPlace") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
<asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
</li>
</InsertItemTemplate>
<ItemSeparatorTemplate>
<br />
</ItemSeparatorTemplate>
<ItemTemplate>
<li style="background-color: #DCDCDC;color: #000000;">SNO:
<asp:Label ID="SNOLabel" runat="server" Text='<%# Eval("SNO") %>' />
<br />
Taxinreal:
<asp:Label ID="TaxinrealLabel" runat="server" Text='<%# Eval("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:Label ID="TaxinpercentLabel" runat="server"
Text='<%# Eval("Taxinpercent") %>' />
<br />
Amount:
<asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
<br />
NetAmount:
<asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:Label ID="DateTakenPlaceLabel" runat="server"
Text='<%# Eval("DateTakenPlace") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul ID="itemPlaceholderContainer" runat="server"
style="font-family: Verdana, Arial, Helvetica, sans-serif;">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<li style="background-color: #008A8C;font-weight: bold;color: #FFFFFF;">SNO:
<asp:Label ID="SNOLabel" runat="server" Text='<%# Eval("SNO") %>' />
<br />
Taxinreal:
<asp:Label ID="TaxinrealLabel" runat="server" Text='<%# Eval("Taxinreal") %>' />
<br />
Taxinpercent:
<asp:Label ID="TaxinpercentLabel" runat="server"
Text='<%# Eval("Taxinpercent") %>' />
<br />
Amount:
<asp:Label ID="AmountLabel" runat="server" Text='<%# Eval("Amount") %>' />
<br />
NetAmount:
<asp:Label ID="NetAmountLabel" runat="server" Text='<%# Eval("NetAmount") %>' />
<br />
DateTakenPlace:
<asp:Label ID="DateTakenPlaceLabel" runat="server"
Text='<%# Eval("DateTakenPlace") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="Differencebutton" runat="server" CommandName="Difference" OnClientClick="Calculate_Difference" Text="Calculate Difference" />
</li>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnString %>"
DeleteCommand="DELETE FROM [tblexpenses] WHERE [SNO] = #SNO"
InsertCommand="INSERT INTO [tblexpenses] ([Taxinreal], [Taxinpercent], [Amount], [NetAmount], [DateTakenPlace]) VALUES (#Taxinreal, #Taxinpercent, #Amount, #NetAmount, #DateTakenPlace)"
SelectCommand="SELECT * FROM [tblexpenses] WHERE ([DateTakenPlace] = #DateTakenPlace2)"
UpdateCommand="UPDATE [tblexpenses] SET [Taxinreal] = #Taxinreal, [Taxinpercent] = #Taxinpercent, [Amount] = #Amount, [NetAmount] = #NetAmount, [DateTakenPlace] = #DateTakenPlace WHERE [SNO] = #SNO">
<DeleteParameters>
<asp:Parameter Name="SNO" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Taxinreal" Type="Double" />
<asp:Parameter Name="Taxinpercent" Type="Decimal" />
<asp:Parameter Name="Amount" Type="Double" />
<asp:Parameter Name="NetAmount" Type="Int32"/>
<asp:Parameter DbType="Date" Name="DateTakenPlace" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="txtCalendar" DbType="Date"
Name="DateTakenPlace2" PropertyName="Text" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Taxinreal" Type="Double" />
<asp:Parameter Name="Taxinpercent" Type="Decimal" />
<asp:Parameter Name="Amount" Type="Double" />
<asp:Parameter Name="NetAmount" Type="Int32" />
<asp:Parameter DbType="Date" Name="DateTakenPlace" />
<asp:Parameter Name="SNO" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
<br />
<br />
<br />
I have a table tblexpense in my database. I have columns named Taxinreal , Taxinpercent,*Amount* NetAmount.*NetAmount* is computed column which is equal to*(Amount-Taxinreal-Taxinpercent)* Now what i want is at runtime in my aspx page the user must be able to insert amount,tax,taxinpercentage and according to the value supplied by user NetAmount must be calculated(Netamount=Amount-Tax-Taxpercentage) at runtime and inserted into the database.For this purpose i have a differencebutton which should perform the required mathematical operation. The problem i am having is i am using a listview. Now adding a new button is simple but how can i perform required mathematical operation in the click event of difference button so that when the listview is in update mode the user can change values of taxinreal ,taxinpercent and obtain the result at runtime and the result be updated in database ??? I need solution urgently(P.S. I need to use Listview only).
You want to use OnItemCommand of ListView.
Here is a sample.
You need to insert/update to database (using either ADO.Net, entity framework or linq-to-sql) in code behind if you want to perform calculation.

how can i use datapager with datalist?

i have a datalist and a datapager but when i run my program it have error.
Control 'DataList1' does not implement IPageableItemContainer.
what is problem?
<asp:DataList ID="DataList1" runat="server" DataKeyField="id"
DataSourceID="SqlDataSource1">
<ItemTemplate>
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
<br />
name:
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
<br />
tedad:
<asp:Label ID="tedadLabel" runat="server" Text='<%# Eval("tedad") %>' />
<br />
group_id:
<asp:Label ID="group_idLabel" runat="server" Text='<%# Eval("group_id") %>' />
<br />
VDate:
<asp:Label ID="VDateLabel" runat="server" Text='<%# Eval("VDate") %>' />
<br />
KDate:
<asp:Label ID="KDateLabel" runat="server" Text='<%# Eval("KDate") %>' />
<br />
gheimat:
<asp:Label ID="gheimatLabel" runat="server" Text='<%# Eval("gheimat") %>' />
<br />
details:
<asp:Label ID="detailsLabel" runat="server" Text='<%# Eval("details") %>' />
<br />
imgae:
<asp:Label ID="imgaeLabel" runat="server" Text='<%# Eval("imgae") %>' />
<br />
"
SelectCommand="SELECT * FROM [Tbl_Kala_Group_No]">
<asp:DataPager ID="DataPager1" runat="server" PagedControlID = "DataList1" PageSize = "4" QueryStringField = "page" >
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
Datapager control does not support for DataList. it works with ListView.
so, Paging for DataList, you have create paging dynamically.
Just give in google : paging for Datalist, you will find lots of resource. Thank you.

Nested User Control (ListView) in ListView doesn't get bound

Hi I am trying to implement a nested user control in listview and the user control doesn't get bound.
Here is my code.
<asp:ListView ID="ListViewTaskList" runat="server" DataKeyNames="TaskID"
DataSourceID="SqlDataSourceTaskList" OnItemDataBound="ListViewTaskListItemDataBound" ItemPlaceholderID="itemPlaceholder">
<LayoutTemplate>
<div class="ListView ">
<div style="font-size:2em;color:#555555;margin-bottom:20px;">Task List</div>
<div ID="itemPlaceholder" runat="server">
</div>
</div>
</LayoutTemplate>
<ItemTemplate>
<div class="rlvI">
<asp:Label ID="TaskIDLabel" runat="server" Text='<%# Eval("TaskID") %>' />
<asp:Label ID="TaskLabel" runat="server" Text='<%# Eval("Task") %>' />
<asp:Label ID="CreatedDateLabel" runat="server" Text='<%# Eval("CreatedDate") %>' />
<asp:Label ID="UpdatedDateLabel" runat="server" Text='<%# Eval("UpdatedDate") %>' />
<asp:Label ID="TimestampLabel" runat="server" Text='<%# Eval("Timestamp") %>' />
<asp:Label ID="TaskTypeIDLabel" runat="server" Text='<%# Eval("TaskTypeID") %>' />
<asp:Label ID="ProjectTaskStatusIDLabel" runat="server" Text='<%# Eval("ProjectTaskStatusID") %>' />
<asp:Label ID="SystemObjectIDLabel" runat="server" Text='<%# Eval("SystemObjectID") %>' />
<asp:Label ID="SystemObjectRecordIDLabel" runat="server" Text='<%# Eval("SystemObjectRecordID") %>' />
<asp:CheckBox ID="ActiveCheckBox" runat="server" Checked='<%# Eval("Active") %>' Enabled="false" />
<asp:Label ID="CreatedByAccountIDLabel" runat="server" Text='<%# Eval("CreatedByAccountID") %>' />
<asp:Label ID="UpdatedByAccountIDLabel" runat="server" Text='<%# Eval("UpdatedByAccountID") %>' />
<asp:Button ID="SelectButton" runat="server" CausesValidation="False" CommandName="Select" CssClass="rlvBSel" Text=" " ToolTip="Select" />
<div>
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' systemObjectRecordID="Comments1Init" />
</div>
</div>
</ItemTemplate>
<AlternatingItemTemplate>
<div class="rlvA">
<asp:Label ID="TaskIDLabel" runat="server" Text='<%# Eval("TaskID") %>' />
<asp:Label ID="TaskLabel" runat="server" Text='<%# Eval("Task") %>' />
<asp:Label ID="CreatedDateLabel" runat="server"
Text='<%# Eval("CreatedDate") %>' />
<asp:Label ID="UpdatedDateLabel" runat="server"
Text='<%# Eval("UpdatedDate") %>' />
<asp:Label ID="TimestampLabel" runat="server"
Text='<%# Eval("Timestamp") %>' />
<asp:Label ID="TaskTypeIDLabel" runat="server"
Text='<%# Eval("TaskTypeID") %>' />
<asp:Label ID="ProjectTaskStatusIDLabel" runat="server"
Text='<%# Eval("ProjectTaskStatusID") %>' />
<asp:Label ID="SystemObjectIDLabel" runat="server"
Text='<%# Eval("SystemObjectID") %>' />
<asp:Label ID="SystemObjectRecordIDLabel" runat="server"
Text='<%# Eval("SystemObjectRecordID") %>' />
<asp:CheckBox ID="ActiveCheckBox" runat="server"
Checked='<%# Eval("Active") %>' Enabled="false" />
<asp:Label ID="CreatedByAccountIDLabel" runat="server"
Text='<%# Eval("CreatedByAccountID") %>' />
<asp:Label ID="UpdatedByAccountIDLabel" runat="server"
Text='<%# Eval("UpdatedByAccountID") %>' />
<asp:Button ID="SelectButton" runat="server" CausesValidation="False"
CommandName="Select" CssClass="rlvBSel" Text=" " ToolTip="Select" />
<div>
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' '<%# Eval("TaskID") %>' />
</div>
</div>
</AlternatingItemTemplate>
``
I have been struggling with this problem for a few days now.
Please help!!
Please help!
if I look at your code, it seems to me that you aren't actually assigning the binding to anything:
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' '<%# Eval("TaskID") %>' />
try instead
<Enet:Comments ID="Comments1" runat="server" systemObjectID='8' YourProperty='<%# Eval("TaskID") %>' />
EDIT: in order to achieve two way data binding, one has to add BindableAttribute to the property on User Control

Resources