Click here to Skip to main content
13,735,231 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">

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

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

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

                                <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;




                    ViewState["datatable"] = dtCurrentTable;

                    grdParticular.DataSource = dtCurrentTable;






                Response.Write("ViewState is null");


Posted 31-Dec-17 23:18pm
Updated 2-Jan-18 20:39pm
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
Please Sign up or sign in to vote.

Solution 1


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
Web04-2016 | 2.8.180920.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