Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnRowEditing="GridView1_RowEditing" AutoGenerateDeleteButton="true" OnRowDeleting="GridView1_RowDeleting" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound" Font-Names="KF-Kiran" ShowFooter="True" TabIndex="16" Width="90%" CellPadding="3" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" GridLines="Horizontal" DataSourceID="SqlDataSource1">
                    <%----%><%--DataSourceID="SqlDataSource1"--%>
                    <Columns>
                        <%--<asp:TemplateField HeaderText="vaaZ" 
                    SortExpression="Saves">
                    <ItemTemplate>
                      <asp:TextBox ID="txtIncrement" runat="server" Width="40px" Text='<%#Eval("Increment") %>'/>
                    </ItemTemplate>
                    <EditItemTemplate>
                         <asp:TextBox ID="txtIncrement" runat="server" Width="40px" Text='<%#Eval("Increment") %>'/>
                    </EditItemTemplate>
                    <%--<FooterTemplate>
                         <asp:TextBox ID="txtIncrement" runat="server" Width="40px"/>
                    </FooterTemplate>
             </asp:TemplateField>--%>
                        <%--<asp:TemplateField HeaderText="vaaZ" 
    SortExpression="Increment2">
    <ItemTemplate>
     <asp:Label ID="txtIncrement2" runat="server" Width="60px" Font-Bold="true" AutoPostBack="true" Text='<%#Eval("Increment2") %>'/>
    </ItemTemplate>
    <EditItemTemplate>
            <asp:Label ID="txtIncrement2" runat="server" Width="60px" Font-Bold="true" Text='<%#Eval("Increment2") %>'/>
    </EditItemTemplate>
    <FooterTemplate>
            <asp:Label ID="txtIncrement2" runat="server" Width="60px"/>
    </FooterTemplate>
</asp:TemplateField>--%>
                        <asp:TemplateField HeaderText="A.kx`." SortExpression="">
                            <ItemTemplate>
                                <b>
                                <asp:Label ID="lblSrNo" runat="server" ForeColor="#cc0000" Text="<%#Container.DataItemIndex+1 %>" />
                                </b>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="kxamaacao naava" SortExpression="Work_Name">
                            <ItemTemplate>
                                <asp:Label ID="txtWork_Name" runat="server" Font-Bold="true" Text='<%#Eval("Work_Name") %>' Width="150px" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtWork_Name" runat="server" Font-Bold="true" Text='<%#Eval("Work_Name") %>' Width="150px" />
                            </EditItemTemplate>
                            <FooterTemplate>
                                <b style="font-family:Arial">Total Calculation:-</b>
                            </FooterTemplate>
                        </asp:TemplateField>

                        


                        <asp:TemplateField HeaderText="ToMxDr" SortExpression="Tender">
                            <ItemTemplate>
                                <asp:TextBox ID="txtTender" runat="server" OnTextChanged="txtTender_TextChanged1" min="1" max="150" MaxLength="3" AutoPostBack="true" Font-Bold="true" Text="0" Width="60px" />
                                <asp:RangeValidator ID="RangeValidator1" Font-Names="arial" runat="server" ErrorMessage="0-150 only" MinimumValue="1" MaximumValue="150" ControlToValidate="txtTender"></asp:RangeValidator>
                                <asp:Label ID="lblError" runat="server" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtTender" runat="server" Font-Bold="true" Width="60px" />
                            </EditItemTemplate>
                        </asp:TemplateField>




    <asp:TemplateField HeaderText="pauiva_ idlaa" SortExpression="Advance">
        <ItemTemplate>
            <asp:TextBox ID="txtAdvance" runat="server" Font-Bold="true" Text="0" Width="60px" />
        </ItemTemplate>
        <EditItemTemplate>
            <asp:TextBox ID="txtAdvance" runat="server" Font-Bold="true" Width="60px" />
        </EditItemTemplate>
    </asp:TemplateField>



                        <asp:TemplateField HeaderText="pa`tyaXa" SortExpression="Real_Val">
                            <ItemTemplate>
                                <asp:TextBox ID="txtReal_Val" runat="server" OnTextChanged="txtReal_Val_TextChanged1" AutoPostBack="true" Font-Bold="true" Text="0" Width="60px" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:TextBox ID="txtReal_Val" runat="server" Font-Bold="true" Width="60px" />
                            </EditItemTemplate>
                        </asp:TemplateField>

                        <asp:TemplateField HeaderText="bacata" SortExpression="Saves">
                            <ItemTemplate>
                                <asp:Label ID="txtSaves" runat="server" Font-Bold="true" Text="0.00" Width="60px" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:Label ID="txtSaves" runat="server" Font-Bold="true" Width="60px" Text='<%#Eval("Saves") %>' />
                            </EditItemTemplate>
                        </asp:TemplateField>
                       
            <asp:TemplateField HeaderText="vaaZ" SortExpression="Increment">
                    <ItemTemplate>
                      <asp:Label ID="txtIncrement" runat="server" Font-Bold="true" Width="40px" Text="0.00"/>
                    </ItemTemplate>
                    <EditItemTemplate>
                      <asp:TextBox ID="txtIncrement" runat="server" Font-Bold="true" Width="40px" Text='<%#Eval("Increment") %>'/>
                    </EditItemTemplate>
             </asp:TemplateField>

                <asp:TemplateField HeaderText="dxr" SortExpression="Rate">
                    <ItemTemplate>
                        <span style="font-family:Arial;font-size:10px">Rs.</span>
                        <asp:Label ID="txtRate" runat="server" AutoPostBack="true" Font-Bold="true" style="font-family:KF-Kiran;" Text='<%#Eval("Rate") %>' Width="50px" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtRate" runat="server" Font-Bold="true" style="font-family:KF-Kiran;" Text='<%#Eval("Rate") %>' Width="50px" />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <span style="font-family:Arial;font-size:15px">Rs.</span>
                        <asp:Label ID="lblTotalRate" runat="server" Font-Bold="true" Font-Size="X-Large" style="font-family:KF-Kiran" Width="50px" />
                    </FooterTemplate>
                </asp:TemplateField>


            <asp:TemplateField HeaderText="ToMxDr" SortExpression="Tender2">
                <ItemTemplate>
                    <asp:Label ID="txtTender2" runat="server" AutoPostBack="true" Font-Bold="true" Text="0.00" Width="60px" />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:Label ID="txtTender2" runat="server" Font-Bold="true" onkeyup="CalculateTotals();" Width="60px" />
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="lblTotalTender2" runat="server" OnTextChanged="lblTotalTender2_TextChanged" Text="0.00" Font-Bold="true" Font-Names="KF-Kiran" />
                </FooterTemplate>
            </asp:TemplateField>



            <asp:TemplateField HeaderText="pa`tyaXa" SortExpression="Real_Val2">
                <ItemTemplate>
                    <asp:Label ID="txtReal_Val2" runat="server" AutoPostBack="true" Font-Bold="true" Text="0.00" Width="60px" />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:Label ID="txtReal_Val2" runat="server" Font-Bold="true" Text='<%#Eval("Real_Val2") %>' Width="60px" />
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblTotalReal_Val" runat="server" Font-Bold="true" Font-Names="KF-Kiran" />
                </FooterTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="bacata" SortExpression="Saves2">
                <ItemTemplate>
                    <asp:Label ID="txtSaves2" runat="server" AutoPostBack="true" Font-Bold="true" Text="0.00" Width="60px" />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:Label ID="txtSaves2" runat="server" Font-Bold="true" Text='<%#Eval("Saves2") %>' Width="60px" />
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblTotalSaves" runat="server" Font-Bold="true" Font-Names="KF-Kiran" />
                </FooterTemplate>
            </asp:TemplateField>

            <asp:TemplateField HeaderText="vaaZ" SortExpression="Increment2">
                <ItemTemplate>
                    <asp:Label ID="txtIncrement2" runat="server" Width="60px" Font-Bold="true" AutoPostBack="true" Text="0.00"/>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:Label ID="txtIncrement2" runat="server" Width="60px" Font-Bold="true" Text='<%#Eval("Increment2") %>'/>
                </EditItemTemplate>
                <FooterTemplate>
                        <asp:Label ID="txtIncrement2" runat="server" Width="60px"/>
                </FooterTemplate>
                <FooterTemplate>
                    <asp:Label ID="lblTotalIncrement" runat="server" Font-Bold="true" Font-Names="KF-Kiran" />
                </FooterTemplate>
            </asp:TemplateField>

                        <asp:TemplateField HeaderStyle-Font-Names="arial" HeaderText="Action">
                            <ItemTemplate>
                                <asp:ImageButton ID="imgEdit" runat="server" CommandName="Edit" Height="20px" ImageUrl="~/Images/edit (9).png" Text="Edit" />
                                <asp:ImageButton ID="imgDelete" runat="server" CommandName="Delete" Height="20px" ImageUrl="~/Images/close (2).png" Text="Delete" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:ImageButton ID="imgUpdate" runat="server" CommandName="Update" Height="20px" ImageUrl="~/Images/Update.png" />
                                <asp:ImageButton ID="imgDelete" runat="server" CommandName="Cancel" Height="20px" ImageUrl="~/Images/Cancel.png" />
                            </EditItemTemplate>
                            <HeaderStyle Font-Names="arial" />
                        </asp:TemplateField>
                    </Columns>
                    <AlternatingRowStyle BackColor="#F7F7F7" />
                    <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                    <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                    <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                    <SortedAscendingCellStyle BackColor="#F4F4FD" />
                    <SortedAscendingHeaderStyle BackColor="#5A4C9D" />
                    <SortedDescendingCellStyle BackColor="#D8D8F0" />
                    <SortedDescendingHeaderStyle BackColor="#3E3277" />
                </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Road_PMCConnectionString %>" SelectCommand="SELECT [Work_Name], [Tender], [Real_Val], [Saves], [Increment], [Rate], [Tender2], [Real_Val2], [Saves2], [Increment2] FROM [tblIncrement_Details]"></asp:SqlDataSource>








CS Code
=======
C#
/////--------Vertical Calculation
try
{
    var footlbl = GridView1.FooterRow.FindControl("lblTotalRate") as Label;
    if (footlbl != null)
    {
        footlbl.Text = stotal.ToString();
    }
}
catch { }






C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            var ratelbl = e.Row.FindControl("txtRate") as Label;
            if (ratelbl != null)
            {
                stotal += Convert.ToDecimal(ratelbl.Text);
            }
        }
     }


What I have tried:

I did single column total but when im trying to do more than one column , it will not work.
Posted
Updated 16-Dec-16 2:10am
Comments
ZurdoDev 9-Dec-16 7:08am    
Why won't multiple columns work? You have code to do one column so multiple columns should be easy. Just find the other control and add to your stotal. Simple. Where are you stuck?
kiran kamble 10-Dec-16 15:08pm    
but another fields are empty , so its throwing null reference exception, plz look at above code and aspx design and try to tell me, how can i do?

1 solution

C#
//After RowDataBound Below lines will loop through Gridview and you find individual Cell Values

foreach (GridViewRow row in GVInvoice.Rows)
{
   if (row.RowType == DataControlRowType.DataRow)
   {
     int index = Convert.ToInt32(row.RowIndex);
     decimal firstColumn = Convert.ToDecimal(GVInvoice.Rows[index].Cells[4].Text);
     decimal secondColumn =Convert.ToDecimal( GVInvoice.Rows[index].Cells[5].Text);
   }
}
//Here You can get cell value of each colummns, if you any control like label or text box, use find control then convert to decimal or int variable depending on your requirement.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900