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

    How to store multiple data in datatable using gridview input.

    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..
  • #764714

    You asked the same question with different title, please review your previous question to get our comments for the same.

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

    Blog :

  • #764729
    Yes agree with Mr. naveensanagasetti.
    refer this URL:

  • #764740

    Please check below code,

    foreach (GridViewRow GridItem in GridView1.Rows)
    strName = GridItem.Cells[1].Text;
    strAddress = GridItem.Cells[2].Text;

    SqlConnection Con = new SqlConnection(clspublic.GetConnectionString());
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = Con;
    cmd.CommandText = @"INSERT INTO Customer
    (Name, Address) VALUES (@Name,@Address)";

    cmd.Parameters.AddWithValue("@Name", strName.ToString());
    cmd.Parameters.AddWithValue("@Address", strAddress.ToString());

    Asheej T K

  • #764755
    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