Click here to Skip to main content
11,705,610 members (47,769 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET
Hai i need to add new row in gridview with textbox and dropdownlist when user clicks

the button in gridview.

please some one help me for getting this solution.
Posted 7-May-12 18:46pm
Prasad_Kulkarni at 8-May-12 9:00am
Glad it helps!
Thank you for 'Accepting Solution'
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

VJ Reddy at 22-May-12 6:25am
Good references. 5!
sravani.v at 22-May-12 6:38am
Thank you Reddy
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Try this:
This example shows how to generate a Row in GridView with TextBoxes when clicking a Button.
Aspx page:
<asp:gridview ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false">
        <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
        <asp:TemplateField HeaderText="Header 1">
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TemplateField HeaderText="Header 2">
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:TemplateField HeaderText="Header 3">
                 <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            <FooterStyle HorizontalAlign="Right" />
             <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" />

Code behind:
private void SetInitialRow()
        DataTable dt = new DataTable();
        DataRow dr = null;
        dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
        dt.Columns.Add(new DataColumn("Column1", typeof(string)));
        dt.Columns.Add(new DataColumn("Column2", typeof(string)));
        dt.Columns.Add(new DataColumn("Column3", typeof(string)));
        dr = dt.NewRow();
        dr["RowNumber"] = 1;
        dr["Column1"] = string.Empty;
        dr["Column2"] = string.Empty;
        dr["Column3"] = string.Empty;
        //dr = dt.NewRow();
        //Store the DataTable in ViewState
        ViewState["CurrentTable"] = dt;
        Gridview1.DataSource = dt;

Page load:
protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)

For more have look on following links:
Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality[^]
Save and Retrieve Dynamic TextBox values in GridView to SQL Server Database[^]

Hope it helps!

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

  Print Answers RSS
0 OriginalGriff 229
1 Sergey Alexandrovich Kryukov 100
2 Inimicos 60
3 ProgramFOX 50
4 Richard MacCutchan 45
0 OriginalGriff 9,053
1 Sergey Alexandrovich Kryukov 8,347
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626

Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 8 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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