You must Sign In to post a response.
  • Category: ASP.NET

    How to add controls dynamically to the gridview.

    Dear Friends
    I have an one gridview. in this gridview i entered more than 10 rows values using input control.. those values should be stored in datatable also bind with gireview.. i implemenred that input controls automatically added in gridview.. how its possible. can any one guide..

    after i stored that data into datatable i click save button for insert data into database..
  • #764671
    Hi navaneethakrishnan.

    I have seen you asking many times with out proper title for your question.
    Instead of asking "need details about gridview, need details about modal popup, datatable so on."
    This will not reflect the actual problem you are facing with.
    Kindly give suitable title for the questions you want to ask that should project the problem you are facing with.
    Hope you understood.

    Sridhar Thota.
    Editor: DNS Forum.

  • #764689
    Hi navaneethakrishnan,

    First up all I agree with Mr. Sridhar, while you are creating any thread it is strictly given that you should "Give meaningful title appropriate to the subject of your message". Hope you will follow such instructions.
    Now for your gridview issue, refer this:
    1) //... Add Gridview to page
    <asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false">
    <input type="text" runat="server" id="txt1" />
    <input type="text" runat="server" id="txt2" />
    2) //... Bind Gridview
    DataTable dt = new DataTable();
    SqlConnection con = new SqlConnection("ConnectionString");
    SqlDataAdapter a = new SqlDataAdapter("SELECT * FROM TableName", con);
    GridView1.DataSource = dt;
    3) //... On Save click, save values to database.
    foreach (DataRow drRow in dt.Rows)

    //.. Or you can traverse to gridview
    HtmlInputControl htmltxt;
    HtmlInputControl htmltxt2;
    foreach (GridViewRow gvRow in GridView1.Rows)
    htmltxt = gvRow.FindControl("txt1") as HtmlInputControl;
    htmltxt2 = gvRow.FindControl("txt2") as HtmlInputControl;
    Hope it helps.
    Shashikant Gurav

  • #764692

    Can you go through the below article and see if it helps. This article is talking about the exact requirement what you have.

    Asheej T K

  • #764709
    Hi NavaneethKrishnan,

    As per my understand the post you want to save the entered details into temporary location and same has been showed into gridview finally the gridview result to be stored into database once click on save button.

    If your requirement is like above then, store the entered details into one temporary location like viewstate and bind the viewstate result into gridview. Whenever you click on save button based on gridview records loop through out the all records and insert one by one into database.

    protected void btnSave_Click(object sender, EventArgs e)
    foreach(GridViewRow row in gv.Rows)
    string Id =((Label(row.FindControl("lblId")).ToString();
    //find all the controls which you want to store and then store the details into database.

    Hope this will helpful to you, if you need any help please let me know...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #764756
    You can do it in two ways.
    First Add the data into the database, then get the data from the database and assign the data souce of the grid view and do databind.
    Add the value in the grid then finally save that into the database

    For the first way.

    1. Design the Input controls for adding the data into the grid view.
    2. Have one button "Add data". In the butting click you can handle the "ADO.NET", for inser the data into the database

    SqlConnection MySqlConnection = new SqlConnection(ConnectionString);
    SqlCommand MySqlCommand = new SqlCommand();
    MySqlCommand .Connection = MySqlConnection ;
    MySqlCommand .CommandText = "Insert statement";
    MySqlCommand .ExecuteNonQuery();

    3. As soon as added the data . Retrieve the data from the database and bind it into the gridview

    You can handle it using Jquery AJAX also.

    By Nathan
    Direction is important than speed

  • Sign In to post your comments