473,779 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView RadioButtonList Values

15 New Member
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 10763
Frinavale
9,735 Recognized Expert Moderator Expert
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
3250
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 SQLDataSource. The GridView contains 3 columns: QuestionNumber, QuestionText, and a TemplateField. Each row in the GridView represents a question in a table (Ex.: "18. Satisfaction Level").
4
2314
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 client has to choose one radiobutton per row (either YES, NO, or PERHAPS). Yes would have a value of 1, No 2, perhaps 3. 1) I need to restrict the choice to one of the three radiobuttons ? 2) Need to insert the client's choice for every row in...
3
13408
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 of a RadioButtonList ("Yes", "No", "Not Answered") in a TemplateColumn. I want the user to be able to select a radio button for each row in the GridView (without having to first put each row into edit mode). Once the user has selected the Radio...
1
1723
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 Eric
5
23634
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" DataField="QuestionID" HeaderText="QuestionID"></asp:BoundField> <asp:BoundField DataField="QuestionDesc" HeaderText="Question" ItemStyle-HorizontalAlign="Left"></ asp:BoundField>
1
2340
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 grid view i have to set in order for this to work? <%@ Page language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> void...
1
1985
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 change True' and 'False' by 'Yes' and 'No' in normal mode. I tried this, but still get True / False. Thanks for help
0
1430
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" runat="server" AutoGenerateColumns="False" DataKeyNames="Question_id" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="q_Description"
13
3519
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 allowing the user to make a selection from the popup window. I have enabled AJAX extensions and have a working sample outside of a gridview. However, when I click in the textbox of a gridview row, all I see is a really small square instead of the...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.