Click here to Skip to main content
13,626,436 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
<asp:GridView ID="grdParticular" runat="server" ShowHeaderWhenEmpty="true" EmptyDataText="No data in gridview" Visible="true" CssClass="table table-striped table-bordered" ShowFooter="True" ShowHeader="true" AutoGenerateColumns="False" DataKeyNames="particula_id">
                    <columns>

                        <asp:TemplateField HeaderText="ID" Visible="false">
                            <itemtemplate>
<asp:HiddenField runat="server" ID="ParID" Value='<%# Eval("particula_id")%>' />
                            
                        


                        <asp:TemplateField HeaderText="Particular">
                            <itemtemplate>
     <asp:TextBox ID="txtPArticular" Text='<%# Eval ("par")%>' runat="server">
                            
                        
                        <asp:TemplateField HeaderText="Result">
                            <itemtemplate>
                                <asp:TextBox ID="txtResult" Text='<%# Eval ("result")%>' runat="server">
                            
                        
                        <asp:TemplateField HeaderText="Unit">
                            <itemtemplate>
                                <asp:TextBox ID="txtUnit" runat="server" Text='<%# Eval ("unit")%>'>
                            

                        
                        <asp:TemplateField HeaderText="Value">
                            <itemtemplate>
                                <asp:TextBox ID="txtValue" runat="server" Text='<%# Eval ("value")%>'>
                            
                        


                        <asp:templatefield>
                            <itemtemplate>
                                <asp:Button ID="ButtonAddNewRow" runat="server" Text="Add Row" OnClick="ButtonAddNewRow_Click" />


What I have tried:

protected void ButtonAddNewRow_Click(object sender, EventArgs e)
        {
            int rowIndex = 0;
            if (ViewState["datatable"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["datatable"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)

                    {

                        //extract the TextBox values

                        TextBox box1 = (TextBox)grdParticular.Rows[rowIndex].Cells[1].FindControl("txtPArticular");

                        TextBox box2 = (TextBox)grdParticular.Rows[rowIndex].Cells[2].FindControl("txtResult");

                        TextBox box3 = (TextBox)grdParticular.Rows[rowIndex].Cells[3].FindControl("txtUnit");

                        TextBox box4 = (TextBox)grdParticular.Rows[rowIndex].Cells[4].FindControl("txtValue");



                        drCurrentRow = dtCurrentTable.NewRow();

                        //drCurrentRow["RowNumber"] = i + 1;



                        dtCurrentTable.Rows[i - 1]["par"] = box1.Text;

                        dtCurrentTable.Rows[i - 1]["Result"] = box2.Text;

                        dtCurrentTable.Rows[i - 1]["Unit"] = box3.Text;

                        dtCurrentTable.Rows[i - 1]["Value"] = box4.Text;

                        rowIndex++;

                    }

                    dtCurrentTable.Rows.Add(drCurrentRow);

                    ViewState["datatable"] = dtCurrentTable;



                    grdParticular.DataSource = dtCurrentTable;

                    grdParticular.DataBind();

                }

            }

            else

            {

                Response.Write("ViewState is null");

            }

}
Posted 31-Dec-17 23:18pm
Updated 2-Jan-18 20:39pm
v2
Comments
Maciej Los 2-Jan-18 7:35am
   
This is not well formed question (if even it is...). You have to provide more details about your issue instead of posting code only.
Hazrat Ali 007 3-Jan-18 1:35am
   
ok thanks sir i have done my problem by getting some help from Net and once again thanks for replying me
‭011111100010‬ 2-Jan-18 11:58am
   
This does not make any sense.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.180712.1 | Last Updated 3 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100