I have problem gridview total

Posted by Nuwan under ASP.NET on 4/4/2012 | Points: 10 | Views : 877 | Status : [Member] | Replies : 1
Dear All...

I bind some data in gridview like Amount,Paid Date, Like that.
I select some month I can retrieve the Details in gridview.
i want to get a total in Amount Field If paid date is Equal to I selected month row total only .
how I do that.

Please help me.

Thank You...

Rathnayake


Responses

Posted by: Self-Innovator on: 4/4/2012 [Member] Bronze | Points: 25

Up
0
Down
In design Mode
<table align="center">

<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Salary"></asp:Label></td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="txtEmail" ErrorMessage="Email required" ValidationGroup="v1"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="EmailExpression" runat="server" ControlToValidate="txtEmail" ErrorMessage="Invalid Email ID" ValidationExpression="^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$" ValidationGroup="v1"></asp:RegularExpressionValidator>
</td>
</tr>
</table>
<asp:GridView ID="GridView1" DataKeyNames="EmpId" runat="server" ShowFooter="True" AutoGenerateColumns="False" AllowSorting="True" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" CellPadding="4" ForeColor="#333333" GridLines="None" PageSize="5" Height="180px">
<Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="Justify" HeaderText="Salary">
<ItemTemplate>
<asp:Label ID="lblEmpSalary" runat="server" Text='<%#Eval("EmpSalary")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtNewEmpSalary" runat="server" Wrap="true" Text='<%#Eval("EmpSalary") %>'></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3" runat="server" ErrorMessage="Salary Required" ControlToValidate="txtNewEmpSalary" ValidationGroup="v2"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Range should be between 1 to 100000" ControlToValidate="txtNewEmpSalary" Type="Integer" ValidationGroup="v2" MaximumValue="100000" MinimumValue="1"></asp:RangeValidator>
</EditItemTemplate>
<FooterTemplate>
<%# gettotal() %> //Calliing the Total Function

</FooterTemplate>
</asp:TemplateField>
<asp:Label ID="lblSalary" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:gridView>


COde Behind
public int GetTotal()

{
SqlConnection cnn = new SqlConnection(Connection);
SqlCommand cmd = new SqlCommand("select sum(EmpSalary) from Employee", cnn);
cnn.Open();
int totalSal = Convert.ToInt32(cmd.ExecuteScalar());
return totalSal;

}


Join Hands Change lives
Thanks & Regards
Straight Edge Society

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response