Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NET
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 18-Feb-13 18:25pm
Comments
Jameel Moideen at 19-Feb-13 0:30am
   
Please post what you have tried
Dhanashree Dive at 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 at 19-Feb-13 0:34am
   
did you tried with check change event of the radio button ?
Dhanashree Dive at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
<itemtemplate>
<asp:RadioButtonList id="rbList" runat="server" AutoPostBack="false"></asp:RadioButtonList>
</itemtemplate>
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();
    }
}
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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi ,
 
Grouped Radio Buttons in Gridview[^]
 
RadioButtons inside a GridView control[^]
 
go with these links it ll help you.
 
Thanks
 
Neha Sharma
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 515
1 OriginalGriff 468
2 Abhinav S 305
3 sanket saxena 295
4 Tadit Dash 160
0 Sergey Alexandrovich Kryukov 8,482
1 OriginalGriff 4,830
2 Peter Leow 3,794
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid