0

I am designing a project in asp.net. I one page i have created a gridview having template field as checkbox. When I select any row in gridview using checkbox,that checked row goes to a new gridview on button click. Now what i want to do is to save that new gridviewin sql. How to save that gridview ????
Pls help.

protected void Button1_Click1(object sender, EventArgs e)
    {
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            DataColumn dc = new DataColumn("id", typeof(int));
            dt.Columns.Add(dc);
            DataColumn dc1 = new DataColumn("name", typeof(string));
            dt.Columns.Add(dc1);
            DataColumn dc2 = new DataColumn("designation", typeof(string));
            dt.Columns.Add(dc2);
            DataColumn dc3 = new DataColumn("group_name", typeof(string));
            dt.Columns.Add(dc3);
            foreach (GridViewRow grow in GridView1.Rows)
            {
                CheckBox cbox = (CheckBox)grow.FindControl("cbox");
                if (cbox.Checked == true)
                {
                    DataRow dr = dt.NewRow();
                    dr["id"] = grow.Cells[1].Text;
                    dr["name"] = grow.Cells[2].Text;
                    dr["designation"] = grow.Cells[3].Text;
                    dr["group_name"] = grow.Cells[4].Text;

                    dt.Rows.Add(dr);
                }
            }
            ds.Tables.Add(dt);
            GridView2.DataSource = ds;
            GridView2.DataBind();

        }
    }
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by tjaank
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.