Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
VB
<asp:Button ID="btn_AddNew" runat="server" CssClass="buttonNormal"
                    Text="Add New" onclick="btn_AddNew_Click"  />



XML
<asp:GridView ID="gv_AparamType" runat="server" AutoGenerateColumns="False"
                                CssClass="gv" EmptyDataText="No Records found"
                                OnRowCancelingEdit="gv_AparamType_RowCancelingEdit"
                                OnRowEditing="gv_AparamType_RowEditing" OnRowUpdating="gv_AparamType_RowUpdating"
                    onselectedindexchanged="gv_AparamType_SelectedIndexChanged" >
                                <Columns>
                                    <asp:TemplateField HeaderText="SL NO">

                                        <ItemTemplate>
                                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("SlNo") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="MODULE">

                                        <ItemTemplate>
                                            <asp:Label ID="Lbl_Module" runat="server" Text='<%# Bind("Module") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="PARAMETERTYPE">

                                        <ItemTemplate>
                                            <asp:Label ID="lbl_PType" runat="server" Text='<%# Bind("ParamType") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="PARAMETERVALUE" itemstyle-width="150">
                                        <EditItemTemplate>
                                            <asp:TextBox ID="txt_PValue" runat="server" Text='<%# Bind("ParamValue") %>' TextMode="MultiLine"></asp:TextBox>
                                        </EditItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label1" runat="server"  Text='<%# Bind("ParamValue") %>'></asp:Label>
                                        </ItemTemplate>
                                       <%-- <ItemStyle Width="1000px" />--%>
                                    </asp:TemplateField>

                                    <asp:CommandField HeaderText="Edit" ShowEditButton="True"  />
                                </Columns>
                            </asp:GridView>

here i have one button "Add New" and I have one "gridveiw" in this gridview i directtly binddata from what ever data is there in my table,,and after that in have one "edit link" is there when i click the that edit link in my gridview column then the 3 rd column data store into "textBox" and i edit and updating.but

my requirement is when i click "addNew" i want add new row that has textbox node for each column into my same "gried view" please can any one help me?
with code allso i want code for"onclick addNew_button" please please
Posted
Updated 5-Oct-17 1:26am
v2

Please try is as below.

Note : This is just a sample.Change it according to your situation.

protected void Button1_Click(object sender, EventArgs e)
   {
       DataTable dt = new DataTable();
       DataColumn dc = new DataColumn();

       if (dt.Columns.Count == 0)
       {
           dt.Columns.Add("PayScale", typeof(string));
           dt.Columns.Add("IncrementAmt", typeof(string));
           dt.Columns.Add("Period", typeof(string));
       }

       DataRow NewRow = dt.NewRow();
       NewRow[0] = TextBox1.Text;
       NewRow[1] = TextBox2.Text;
       dt.Rows.Add(NewRow); 
       GridView1.DataSource = dt;
       GridViewl.DataBind();
   }


Check here for more info : add new row in gridview after binding C#, ASP.net

Add new Row to GridView on Button Click in ASP.Net
 
Share this answer
 
v2
The datatable bound to the grid, assume the datatable is dtGrid. Save that in a ViewState/Session
Below I have provided a sample code. I hope this gives you an idea to build on...
This code will add empty row...
C#
OnAddNew_Click()
{
dtGrid=(DataTable)ViewState["dt"];
DataRow dr = dtGrid.NewRow();
dr[0]=""
dr[1]=""
dr[2]=""
dr[3]=""
dr[4]=""
dtGrid.Rows.Add(dr);
gridView.DataSource=dtGrid;
gridView.DataBind();
}



Hope this helps
 
Share this answer
 

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