Click here to Skip to main content
15,892,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is the code snippet
XML
<asp:TemplateField HeaderText="Weighting Factor">
                                   <ItemTemplate>
                                       <asp:TextBox ID="txtweight_fact" runat="server" Height="41px" Width="42px"
                                           MaxLength="4"></asp:TextBox>
                                       <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
                                           ControlToValidate="txtweight_fact" ErrorMessage="*" ValidationGroup="valgrp_func"></asp:RequiredFieldValidator>
                                       <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                                           ControlToValidate="txtweight_fact" ErrorMessage="Numbers Only "
                                           ValidationExpression="[0-9.]+" ValidationGroup="valgrp_func"
                                           Font-Names="Verdana" Font-Size="XX-Small"></asp:RegularExpressionValidator>
                                   </ItemTemplate>
                                    <HeaderStyle Width="30px" />
                                   <ItemStyle Width="30px" />
                                   <FooterTemplate>
                                   <center>
                                          <asp:TextBox ID="txttotal" runat="server" Width="113px"></asp:TextBox>
                                          <asp:Button ID="BtnAdd" runat="server" OnClick="ButtonAdd_Click" ValidationGroup="valgrp_func"
                               Text="Add" /></center>
                                   </FooterTemplate>
                                   <FooterStyle HorizontalAlign="Right" />
                               </asp:TemplateField>


Here i want add the values of the dynamically created textbox to the txttotal
Am not aware of C# so please post your help in VB .
Posted
Updated 10-Feb-14 22:01pm
v3

Please Try This
C#
decimal total=0.0;

for (int i=0;i<gv.Rows.Count;i++)
{
  TextBox txtTotal = (TextBox)gv.Rows[i].FindControl("txtTotal");
  total+=Convert.ToDecimal(txtTotal.Text);
}


Regards,
Dinesh Kumar.V.
 
Share this answer
 
Comments
Ni!E$H_WAGH 11-Feb-14 2:13am    
This code goes to ?
Dinesh.V.Kumar 11-Feb-14 2:15am    
Try this code in say..any button event...for example..btnCalculate or btnSave...

Regards,
Dinesh Kumar.V.
Ni!E$H_WAGH 11-Feb-14 2:17am    
K Thanks
Dinesh.V.Kumar 11-Feb-14 2:19am    
You are welcome!!!

Regards,
try this

C#
int total = 0;
       protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               TextBox txtweight_fact = (TextBox)e.Row.FindControl("txtweight_fact");
               total += Convert.ToInt32(txtweight_fact.Text.Trim());
           }
           if (e.Row.RowType == DataControlRowType.Footer)
           {
               TextBox txttotal = (TextBox)e.Row.FindControl("txttotal");
               txttotal.Text = total.ToString();
           }
       }
 
Share this answer
 
Comments
Ni!E$H_WAGH 11-Feb-14 2:16am    
Thanks
OPees 11-Feb-14 2:17am    
:)
Ni!E$H_WAGH 11-Feb-14 2:29am    
Tried your solution but getting another error
in the given code
Dim str As String = txtweight_fact.Text.ToString
total = total + Convert.ToDouble(str) as
Input string was not in a correct format.
OPees 11-Feb-14 3:18am    
use Double.TryParse
OPees 11-Feb-14 3:22am    
see the link

http://www.codeproject.com/Questions/448466/Input-string-was-not-in-a-correct-format-Convert-T
C#
<gridviewrow footerrow="GV.FooterRow" mode="hold" />                    if (footerRow != null)
                    {
                        int? totalSum = 0; Double totalwt = 0;
                        double totalamount = 0;
                        foreach (DataColumn c in DynamicGV.Columns)
                        {

                            if (c.ColumnName == "txtweight_fact")
                            {
                                int? sum = 0;
                                foreach (DataRow rw in dtdcDetails.Rows)
                                {
                                    sum = sum + Convert.ToInt32(rw[c].ToString());
                                    footerRow.Cells[dtdcDetails.Columns.IndexOf(c.ColumnName)].Text = sum.ToString();
                                }
                                totalSum = totalSum + sum;
                            }
                       } 
                     }
 
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