Hi,
This is sridhar,i m adding checkbox controls dynamically in asp.net gridview like this
CheckBox cb = new CheckBox();
cb.EnableViewState = true;
cb.ID = "chkbox" ;
GridView1.Rows[j].Cells[mcount].Controls.Add(cb);
and i want to access that checkbox is checked or not on button click event....
Any one Help me...
With Regards
S.Sridhar

Manas MohapatraRank #182 · 13.2K reputationPosted Aug 14, 2015, 7:12 AM EDT
sri dar48 reputationPosted Aug 14, 2015, 7:25 AM EDT
Vicky Bhatt67 reputationPosted Aug 14, 2015, 9:06 PM EDT
RowDataBoundis just triggered when you databind theGridViewwhat is done typically onlyif(!IsPostBack)(at the first time the page loads).You should create dynamic controls in
RowCreatedinstead which is called on every postback. You can databind these controls then inRowDataBoundif you want, sinceRowCreatedis triggered first.protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { CheckBox chk = new CheckBox(); chk.EnableViewState = true; chk.Enabled = true; chk.ID = "chkb"; e.Row.Cells[1].Controls.Add(chk); } } protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { var chk = (CheckBox)e.Row.FindControl("chkb"); // databind it here according to the DataSource in e.Row.DataItem } }sri dar48 reputationPosted Aug 14, 2015, 10:04 PM EDT
Manas MohapatraRank #182 · 13.2K reputationPosted Aug 15, 2015, 5:06 AM EDT