datagrid with chek boxes
hi i am having two pages having datagrid.
so, i want to select some rows in select.aspx and click on button then selected rows are automatically dispalyed in the displayitems.aspx in datagrid.
here my coding not gives the proper result.
select.aspx:-
-----------------
private void Button1_Click(object sender, System.EventArgs e)
{
DataTable dt=new DataTable();
DataRow dr;
dt.Columns.Add("productid");
dt.Columns.Add("productname");
foreach (DataGridItem item in DataGrid1.Items)
{
CheckBox Check=new CheckBox();
Check=(CheckBox)item.FindControl("chk");
if (Check.Checked==true)
{
dr=dt.NewRow();
dr[0]= item.Cells[0].Text;
dr[1]=item.Cells[1].Text;
dt.Rows.Add(dr);
}
}
Session["details"]=dt;
Response.Redirect("displayitems.aspx");
}
}
}
displayitems.aspx:-
-----------------------
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!Page.IsPostBack)
{
DataTable dt1=new DataTable();
dt1=(DataTable)Session["details"];
DataGrid1.DataSource=dt1.DefaultView;
DataGrid1.DataBind();
}
}
|