i like to know how i have to use radio button CheckedChanged property when the radio button there is in gridview and this gridview itself is inside of 1 user control and user control is inside of detail view control.
before i have learned how i have to find radio button control in another control. but after finding i do not know how to make CheckedChanged property for that?
protected void btnShowAddTransmittaltoCon_Click(object sender, EventArgs e)
{
Transmittallistfortest transmittalList = (Transmittallistfortest)DetailsView1.FindControl("Transmittallistfortest1");
GridView g3 = transmittalList.FindControl("GridViewTtransmittals") as GridView;
foreach (GridViewRow di in g3.Rows)
{
RadioButton rad = (RadioButton)di.FindControl("RadioButton1");
//Giving Error:Object reference not set to an instance of an object.
if (rad != null && rad.Checked)
{
var w = di.RowIndex;
Label1.Text = di.Cells[1].Text;
}
Replace this
with this:
You won’t get an exception but it may return
NULL– in which case it’ll be caught in theifstatement:rad != null.The whole point of using the
askeyword is this:By the way: You should retrieve the
RadioButtonthis way:To define the
CheckedChangeevent, do this:Then define the handler: