That depends on where do you want to access it. If you want it at
RowDataBound
event, then you need to make sure you are checking for the appropriate
DataControlRowType
first before using
FindControl
method. For example:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
RadioButtonList rblHeader = (RadioButtonList)e.Row.FindControl("rblYesNoPos");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButtonList rblRow = (RadioButtonList)e.Row.FindControl("rblYesNoRe");
}
}
If want to reference them at
Button Click
event where your Button is inside the
GridView
template, then you can do something like this:
protected void Button1_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
GridViewRow row = (GridViewRow)b.NamingContainer;
if (row != null)
{
if (row.RowType == DataControlRowType.Header)
{
RadioButtonList rblHeader = (RadioButtonList)row.FindControl("rblYesNoPos");
}
if (row.RowType == DataControlRowType.DataRow)
{
RadioButtonList rblRow = (RadioButtonList)row.FindControl("rblYesNoRe");
}
}
}