I have added control by
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chk = new CheckBox();
chk.EnableViewState = true;
chk.Enabled = true;
chk.ID = "chkb";
DataRowView dr = (DataRowView)e.Row.DataItem;
chk.Checked = (dr[0].ToString() == "true");
e.Row.Cells[1].Controls.Add(chk);
e.Row.TableSection = TableRowSection.TableBody;
}
and trying to find by
if (GridView2.Rows.Count>0)
{
foreach (GridViewRow row in GridView2.Rows)
{
CheckBox cb =(CheckBox) GridView2.Rows[2].Cells[1].FindControl("chkb");
if (cb != null && cb.Checked)
{
Response.Write("yest");
}
}
}
But i cannot find it …
Actually my problem is that i need to create a dynamic list.. for that i am using gridview
You need to create dynamic controls on every postback since it is disposed at the end of the current life-cycle. But
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.