473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

GridView RadioButtonList Values

15
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!!!!!
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" GridLines="None">
  2.  
  3. <Columns>
  4.  
  5. <asp:TemplateField SortExpression="Question_Text">
  6.  
  7.     <EditItemTemplate>
  8.         <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Question_Text")>'>/asp:TextBox>
  9.     </EditItemTemplate>
  10.  
  11.     <ItemTemplate>
  12.         <asp:Label ID="Label10" runat="server" Text='<%# Bind("Question_Text") %>'></asp:Label>
  13.         <asp:RadioButtonList ID="RadioButtonList1" Visible='<%# GetRadioSetting(Eval("Answer_Type")) %>' runat="server" RepeatColumns="5" RepeatDirection="Horizontal" RepeatLayout="Flow" Width="400px">
  14.             <asp:ListItem>N/A</asp:ListItem>
  15.             <asp:ListItem>1</asp:ListItem>
  16.             <asp:ListItem>2</asp:ListItem>
  17.             <asp:ListItem>3</asp:ListItem>
  18.             <asp:ListItem>4</asp:ListItem>
  19.         </asp:RadioButtonList>
  20.     </ItemTemplate>
  21.  
  22. </asp:TemplateField>
  23.  
  24. <asp:TemplateField SortExpression="Question_Number" Visible="False">
  25.     <EditItemTemplate>
  26.         <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Question_Number") %>'></asp:TextBox>
  27.     </EditItemTemplate>
  28.     <ItemTemplate>
  29.         <asp:Label ID="Label2" runat="server" Text='<%# Bind("Question_Number") %>'></asp:Label>
  30.     </ItemTemplate>
  31. </asp:TemplateField>
  32.  
  33. </Columns>
  34.  
  35. </asp:GridView>
  36.  
  37. <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
  38.  
Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2. {
  3.     IDictionary<int, string> values = new Dictionary<int, string>();
  4.  
  5.     foreach (GridViewRow row in GridView1.Rows)
  6.     {
  7.         // Assuming Question_Number is placed into DataKeyNames property
  8.         int questionNumber = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
  9.  
  10.         RadioButtonList lst = row.FindControl("RadioButtonList1") as RadioButtonList;
  11.         string answer = (lst != null) ? lst.SelectedValue.ToString() : String.Empty;
  12.  
  13.         values.Add(questionNumber, answer);
  14.     }
  15.  
  16. }
  17.  
questionNumber value is coming correct.but answer="" for all the questions.

PLEASE ADVISE.....
Feb 10 '09 #1
1 10740
Frinavale
9,735 Expert Mod 8TB
Is your GridView in Edit Mode when the button is clicked?
If so, your RadioButtonList wont exist.

Are you, by any chance, binding the Data to the GridView during the Page Load event?
If so then you'll lose what the user has selected.
Feb 11 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
4
by: Patrik | last post by:
hello, based on a client login I call a GridView that presents the appropriate questionnaire for that person. I added three columns (template fields) to the gridview that are radiobuttons. The...
3
by: cpnet | last post by:
I have a GridView which I'm populating from an ObjectDataSource (give the GridView a DataTable). The GridView will have about 20 rows, and only one editable column. The editable column consists...
1
by: Eric Effer | last post by:
Hi everyone I am tryin to get the selected index from this gridview while selecting the radiobuttonlist. I dont want to use a button for the row though. Anyone knows how to do this? thnks ...
5
by: NKaufman | last post by:
<asp:GridView ID="Basic" runat="server" DataKeyNames="QuestionID,isHeading" AutoGenerateColumns="false" AllowPaging="true" PageSize="100"> <Columns> <asp:BoundField Visible="false"...
1
by: l3d007 | last post by:
I used this example straight from msdn in a gridview that already sorts based on each column. For some reason I cannot get it to sort based on two sorting expressions.Is there some property of the...
1
by: Ben | last post by:
Hi, The gridview contains a radiobuttonlist with boolean values (true/false) coming from a database. In normal mode, the gridview displays True or False for that field. What i want is to...
0
by: =?Utf-8?B?QW5keSBpbiBTb3V0aCBKZXJzZXk=?= | last post by:
I want to use a RadioButtonList Control(HTML) in a GridView control. I can see the RadioButtonList control with each row in the GridView with the code: <asp:GridView ID="GridView1"...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.