Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview. In that I have four radio button with its group name. when I select any one radio button from gridview, I want the respected text of that radio button.
Posted
Comments
Jameel VM 19-Feb-13 0:30am    
Please post what you have tried
Dhanashree Dive 19-Feb-13 0:33am    
protected void lbtnsubmit_Click(object sender, EventArgs e)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
RadioButton rb = (GridView1.Rows[i].FindControl("answer")) as RadioButton;
if (rb.Checked == true)
{
asnw.Text =GridView1.Rows[i].Cells[1].Text;
}
}
}
This is the code which I m have written on button click. But I also have one doubt. Do I need to write all radio button as listItem in radiobuttonList? and if I write radiobuttonlist then i m binding four radio button as ->
<asp:listitem text='<#eval('column1')>'<asp:listitem>
ans so on. please help me.
Karthik Harve 19-Feb-13 0:34am    
did you tried with check change event of the radio button ?
Dhanashree Dive 19-Feb-13 0:39am    
I have not created radio button list. And so I m getting problem in firing any event. please tell me how should I write four radio buttons in radiobuttonlist.

Hi ,

Grouped Radio Buttons in Gridview[^]

RadioButtons inside a GridView control[^]

go with these links it ll help you.

Thanks

Neha Sharma
 
Share this answer
 
Hi,

you can use RadioButtonList in the ItemTemplate of the gridview and in RowDataBound event of the gridview, you can bind the items of the list.

ASP.NET
<itemtemplate>
<asp:RadioButtonList id="rbList" runat="server" AutoPostBack="false"></asp:RadioButtonList>
</itemtemplate>

C#
protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        RadioButtonList list = (RadioButtonList)e.Row.FindControl("rbList");
        list.DataSource = objDT; //your datatable as datasource
        list.DataBind();
    }
}

C#
protected void lbtnsubmit_Click(object sender, EventArgs e) 
{
    for (int i = 0; i < GridView1.Rows.Count; i++) 
    { 
        RadioButtonList rblist = (GridView1.Rows[i].FindControl("rbList")) as RadioButtonList; 
        if (rblist.SelectedItem != null) 
        { 
            asnw.Text = rbList.SelectedItem.Text;
        } 
    }
}


hope it helps
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900