5
Answers

RadioButton control in every row of the GridView control to select one row at a time?

Vikas Ahlawat

Vikas Ahlawat

13y
4.6k
1
I have taken RadioButton control in every row of the GridView control to select one row at a time. (asp.net C#)
for this i write the following code, But it is slow process, I want to best way to do this

        protected void RadioButton1_CheckedChanged1(object sender, EventArgs e)
        {
            RadioButton SelectedRadioButton = (RadioButton)sender;

            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                RadioButton rb = (RadioButton)GridView1.Rows[i].FindControl("RadioButton1");
                rb.Checked = false;

            }
            GridViewRow SelectedGridRow = (GridViewRow)SelectedRadioButton.NamingContainer;  //for get the index of selected row
            int RowIndex = SelectedGridRow.RowIndex;
            RadioButton rb1 = (RadioButton)GridView1.Rows[RowIndex].FindControl("RadioButton1");
            rb1.Checked = true;
            
        }

is there any suggestion?

Answers (5)