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

    Need detail about gridview

    Dear Friends
    In my project i have one gridview with add button and input control text box ,
    when i was click that add button my all put should be saved in datatable and that datatable value should display in gridview.. these all operation fire only with out database..

    when i was click "Save" button the gridview values are store into database. can any one guide..
  • #764613
    Try this:
    protected void btnAdd_Click(object sender, EventArgs e)
    DataTable dtTable = new DataTable();
    DataRow drRow;
    dtTable.Columns.Add(new System.Data.DataColumn("Col1", typeof(String)));
    drRow = dtTable.NewRow();
    drRow[0] = txtYourInputTextBox.Text;
    GridView1.DataSource = dtTable;
    drRow = null;
    dtTable = null;

    protected void btnSave_Click(object sender, EventArgs e)
    foreach (GridViewRow gvRow in GridView1.Rows)
    string szData = gvRow.Cells[0].ToString();
    //... Now insert szData in DB ...
    Hope it helps.
    Shashikant Gurav

  • #764616

    If you want to save the gridview row information based on click, then use OnRowCommand event and save the particular row inforamtion into database.


    protected void gv_OnRowCommand(object sender,GridviewRowCommandEventArgs e)
    //save data into database.

    If you want to save all the records into database then onclick event of button loop through all rows of gridview and save it into database.

    protected void btnsave_click(object sender, EventArgs e)
    foreach(GridviewRow row in gv.Rows)
    //save each row into database...

    Hope this will helpful to you...

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

    Blog :

  • #764623
    Hi navaneethakrishnan.

    If you want the details to be shown after adding the records inline then bind the gridview with datatable.

    With in the add_btn_click event you can make the datasource as datatable and bind the gridview like below

    DataTable dt=new DataTable();
    GridView1.DataSource = dt;

    With in the save_btn_click you can save those records to the database.

    Sridhar Thota.
    Editor: DNS Forum.

  • #764656
    Below articles will help you find sample code in this regard,

    Asheej T K

  • Sign In to post your comments