GridView RadioButtonList Values

Feb 10, 2009
Reaction score
Hello friends please advise.......

I am building an application for Survey. For this i have GridView with two Template fields. The first Template has Label (To display question text) and RadioButtonList (for options). The 2nd Template field is the primary key value. And i have a button on the form.

In the button click event i wrote code to grab RadioButtonList values.But the selected value is coming as null....PLEASE ADVISE....

Let me know if my question is unclear!!!!!

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" GridLines="None">


<asp:TemplateField SortExpression="Question_Text">


<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Question_Text") %>'></asp:TextBox>



<asp:Label ID="Label10" runat="server" Text='<%# Bind("Question_Text") %>'></asp:Label>

<asp:RadioButtonList ID="RadioButtonList1" Visible='<%# GetRadioSetting(Eval("Answer_Type")) %>' runat="server" RepeatColumns="5" RepeatDirection="Horizontal"

RepeatLayout="Flow" Width="400px">









<asp:TemplateField SortExpression="Question_Number" Visible="False">


<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Question_Number") %>'></asp:TextBox>



<asp:Label ID="Label2" runat="server" Text='<%# Bind("Question_Number") %>'></asp:Label>





<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />

protected void Button1_Click(object sender, EventArgs e)

IDictionary<int, string> values = new Dictionary<int, string>();

foreach (GridViewRow row in GridView1.Rows)
// Assuming Question_Number is placed into DataKeyNames property
int questionNumber = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);

RadioButtonList lst = row.FindControl("RadioButtonList1") as RadioButtonList;
string answer = (lst != null) ? lst.SelectedValue.ToString() : String.Empty;

values.Add(questionNumber, answer);


questionNumber value is coming correct.but answer="" for all the questions.



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question