Click here to Skip to main content
15,896,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have Two Gridview If in First Gridview have a checkbox also. I take an Add Button outside the gridview. If I select Checkbox and click Add Button particular selected rows are deleted in FirstGrid view and Inserted in second gridview but not insert and delete process in Database only in Gridview dataset.
Posted
Updated 26-Sep-11 1:35am
v3
Comments
chinta123 26-Sep-11 6:21am    
http://csharpdotnetfreak.blogspot.com/2009/05/gridview-sqldatasource-insert-edit.html just go through this link.

1 solution

Please try this one.It May help you

protected void Button1_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataRow dr;

        dt.Columns.Add(new DataColumn("ColumnName1"));
        dt.Columns.Add(new DataColumn("ColumnName2"));
        dt.Columns.Add(new DataColumn("ColumnName3"));

        foreach (GridViewRow gvr in GridView1.Rows)
        {            
            if (((CheckBox)gvr.Cells[4].FindControl("CheckBox")).Checked == true)
            {
                dr = dt.NewRow();
                dr["ColumnName1"] = ((Label)gvr.Cells[0].FindControl("Label")).Text;
                dr["ColumnName2"] = ((Label)gvr.Cells[1].FindControl("Label")).Text;
                dr["ColumnName3"] = ((Label)gvr.Cells[2].FindControl("Label")).Text;
                dt.Rows.Add(dr);
            }
        }

        foreach (GridViewRow gvr in GridView2.Rows)
        {
            dr = dt.NewRow();
            dr["ColumnName1"] = ((Label)gvr.Cells[0].FindControl("Label")).Text;
            dr["ColumnName2"] = ((Label)gvr.Cells[1].FindControl("Label")).Text;
            dr["ColumnName3"] = ((Label)gvr.Cells[2].FindControl("Label")).Text;
            dt.Rows.Add(dr);
        }

        GridView2.DataSource = dt;
        GridView2.DataBind();
    }


After binding Grid2, Write the code to delete selected rows from Grid1.
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900