Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView RadioButtonList Values

Thread Tools

GridView RadioButtonList Values

renuami renuami is offline
Junior Member
Join Date: Feb 2009
Posts: 2
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.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
RadioButtonList(HTML) Control in a GridView Andy in South Jersey ASP .Net 0 07-07-2008 02:18 PM
problem with displaying radiobuttonlist value in gridview Ben ASP .Net Web Controls 5 06-02-2008 06:15 PM
can't change radiobuttonlist displayed value in normal mode of gridview Ben ASP .Net 1 05-29-2008 07:22 PM
gridview column values to another page via gridview hyperlink column Keith G Hicks ASP .Net 3 02-18-2008 06:17 AM
Updating Gridview with Radiobuttonlist James ASP .Net 3 12-15-2007 01:28 PM