473,385 Members | 1,465 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,385 software developers and data experts.

How to retrieve a value from a set of radio buttons

Rob

Hi all,
I've got multiple sets of radio button that are dynamically created in
code and populated by a database query. The query returns about 20
recordsets with 3 radio buttons per recordset and I want to be able to
retrieve the selected value from each of the sets of radio buttons.The
names of each group of radio buttons is set by the database and I don't
know how to retrieve the values because I don't know the names of these
radio buttons.Is there any way of retrieving the values without going to
the database again?

Here's the code to populate the radio buttons:

Any help would be appreciated.
Thanks
Rob

Private Sub DisplayGames()
Dim rb1 As RadioButton
Dim rb2 As RadioButton
Dim rbTie As RadioButton
Dim tr As TableRow
Dim td1 As TableCell
Dim td2 As TableCell
Dim td3 As TableCell
Dim tdVimage As TableCell
Dim vImage As Image
Dim tdHimage As TableCell
Dim hImage As Image
Dim trDate As TableRow
Dim tdDate As TableCell
Dim prevDate As Date

Dim cn As New
SqlConnection(ConfigurationSettings.AppSettings("C ONN_STRING"))
Dim cm As New SqlCommand("sp_show_games", cn)
cm.CommandType = CommandType.StoredProcedure

cn.Open()

tblPlayGames.CellPadding = 1
tblPlayGames.CellSpacing = 2

Try
Dim dr As SqlDataReader =
cm.ExecuteReader(CommandBehavior.CloseConnection)
Do While dr.Read
'display the date
If prevDate <> dr.GetDateTime(1).ToLongDateString Then
trDate = New TableRow
trDate.BackColor = Color.DarkBlue
tdDate = New TableCell
tdDate.ColumnSpan = 5
tdDate.CssClass = "sm_text"
tdDate.Font.Bold = True
tdDate.ForeColor = Color.White
tdDate.Text = dr.GetDateTime(1).ToLongDateString
trDate.Controls.Add(tdDate)
tblPlayGames.Controls.Add(trDate)
End If

tr = New TableRow
'add an image for the visitor to the cell
vImage = New Image
vImage.ImageUrl = "images/teams/" & dr.GetString(4)
tdVimage = New TableCell
tdVimage.Controls.Add(vImage)
tr.Controls.Add(tdVimage)

'add a radio button for the visitor
td1 = New TableCell
rb1 = New RadioButton
rb1.GroupName = dr.GetInt32(0)
rb1.ID = dr.GetInt32(0) & "_" & dr.GetString(2)
rb1.CssClass = "team_text"
rb1.Text = dr.GetString(2)
td1.Controls.Add(rb1)
tr.Controls.Add(td1)

'add a radio button for the tie
td2 = New TableCell
td2.BackColor = Color.LightGray
rbTie = New RadioButton
rbTie.GroupName = dr.GetInt32(0)
rbTie.ID = dr.GetInt32(0) & "_0"
rbTie.CssClass = "team_text"
rbTie.Text = "Tie"
td2.Controls.Add(rbTie)
tr.Controls.Add(td2)
'add an image for the home team
hImage = New Image
hImage.ImageUrl = "images/teams/" & dr.GetString(5)
tdHimage = New TableCell
tdHimage.Controls.Add(hImage)
tr.Controls.Add(tdHimage)

'add a radio button for the home team
td3 = New TableCell
rb2 = New RadioButton
rb2.GroupName = dr.GetInt32(0)
rb2.ID = dr.GetInt32(0) & "_" & dr.GetString(3)
rb2.CssClass = "team_text"
rb2.Text = dr.GetString(3)
td3.Controls.Add(rb2)
tr.Controls.Add(td3)

'add all controls to the table
tblPlayGames.Controls.Add(tr)
prevDate = dr.GetDateTime(1).ToLongDateString

Loop
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

End Sub
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
2 5404
Dear Rob,

To retrieve the selected value of all radio buttons, I have written an
article.

Please check My Blog, as below:-

http://aspnet_harish.blogspot.com/20...-all-list.html

This should help you.

Thanks.

"Rob" wrote:

Hi all,
I've got multiple sets of radio button that are dynamically created in
code and populated by a database query. The query returns about 20
recordsets with 3 radio buttons per recordset and I want to be able to
retrieve the selected value from each of the sets of radio buttons.The
names of each group of radio buttons is set by the database and I don't
know how to retrieve the values because I don't know the names of these
radio buttons.Is there any way of retrieving the values without going to
the database again?

Here's the code to populate the radio buttons:

Any help would be appreciated.
Thanks
Rob

Private Sub DisplayGames()
Dim rb1 As RadioButton
Dim rb2 As RadioButton
Dim rbTie As RadioButton
Dim tr As TableRow
Dim td1 As TableCell
Dim td2 As TableCell
Dim td3 As TableCell
Dim tdVimage As TableCell
Dim vImage As Image
Dim tdHimage As TableCell
Dim hImage As Image
Dim trDate As TableRow
Dim tdDate As TableCell
Dim prevDate As Date

Dim cn As New
SqlConnection(ConfigurationSettings.AppSettings("C ONN_STRING"))
Dim cm As New SqlCommand("sp_show_games", cn)
cm.CommandType = CommandType.StoredProcedure

cn.Open()

tblPlayGames.CellPadding = 1
tblPlayGames.CellSpacing = 2

Try
Dim dr As SqlDataReader =
cm.ExecuteReader(CommandBehavior.CloseConnection)
Do While dr.Read
'display the date
If prevDate <> dr.GetDateTime(1).ToLongDateString Then
trDate = New TableRow
trDate.BackColor = Color.DarkBlue
tdDate = New TableCell
tdDate.ColumnSpan = 5
tdDate.CssClass = "sm_text"
tdDate.Font.Bold = True
tdDate.ForeColor = Color.White
tdDate.Text = dr.GetDateTime(1).ToLongDateString
trDate.Controls.Add(tdDate)
tblPlayGames.Controls.Add(trDate)
End If

tr = New TableRow
'add an image for the visitor to the cell
vImage = New Image
vImage.ImageUrl = "images/teams/" & dr.GetString(4)
tdVimage = New TableCell
tdVimage.Controls.Add(vImage)
tr.Controls.Add(tdVimage)

'add a radio button for the visitor
td1 = New TableCell
rb1 = New RadioButton
rb1.GroupName = dr.GetInt32(0)
rb1.ID = dr.GetInt32(0) & "_" & dr.GetString(2)
rb1.CssClass = "team_text"
rb1.Text = dr.GetString(2)
td1.Controls.Add(rb1)
tr.Controls.Add(td1)

'add a radio button for the tie
td2 = New TableCell
td2.BackColor = Color.LightGray
rbTie = New RadioButton
rbTie.GroupName = dr.GetInt32(0)
rbTie.ID = dr.GetInt32(0) & "_0"
rbTie.CssClass = "team_text"
rbTie.Text = "Tie"
td2.Controls.Add(rbTie)
tr.Controls.Add(td2)
'add an image for the home team
hImage = New Image
hImage.ImageUrl = "images/teams/" & dr.GetString(5)
tdHimage = New TableCell
tdHimage.Controls.Add(hImage)
tr.Controls.Add(tdHimage)

'add a radio button for the home team
td3 = New TableCell
rb2 = New RadioButton
rb2.GroupName = dr.GetInt32(0)
rb2.ID = dr.GetInt32(0) & "_" & dr.GetString(3)
rb2.CssClass = "team_text"
rb2.Text = dr.GetString(3)
td3.Controls.Add(rb2)
tr.Controls.Add(td3)

'add all controls to the table
tblPlayGames.Controls.Add(tr)
prevDate = dr.GetDateTime(1).ToLongDateString

Loop
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

End Sub
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
Rob

Thanks ranganh,

I've tried that and I was getting an invalid cast exception when trying
to cast to a RadioButtonList. I guess I'll have to use a RadioButtonList
to use your example. As it is I'm generating radio buttons on the fly
and assigning them to a group.

I'll test it with A RadioButtonList.

Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eric Chang | last post by:
I was working on this simple form with radio boxes. And when I click on one of the radio box, it tell me the value is "undefined" Why is that ? I did defined the value of each radio box: ...
4
by: Randell D. | last post by:
Folks, I have a form (called FORM1) - In my INPUT submit tag, I have an onClick event that I have successfully tested/used to display the value of a TEXT box using the following function (called...
3
by: Flip | last post by:
In setting up a radio button group last night, I added two radio buttons, gave each of them their respective name and gave them both the same group name. So far so good. But then when I tried to...
7
by: deepagulati | last post by:
Hi, I need an urgent help from you. When we dynamically genrate any list box (Select Box) it shows one default value as selected. Is there any way that we can deselect that value. I...
0
by: larry jackson | last post by:
hello all im new to ASP. Net im using C# as the code behind problem: i created a form ( poll.aspx) that uses asp radio buttons so that the user can select an item. i want to retrieve and write...
1
by: Mufasa | last post by:
I have a couple of radio buttons that make various things appear/disappear on the screen through JavaScript. All works great. Problem is I'll click a radio button, something will appear, I reload...
3
by: romano2717 | last post by:
I have a test.php file that contains a set of radio buttons generated inside a loop. then I append the $i variable to the radio button name to have a unique set of radio buttons. the scenario...
1
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
2
by: pilankooveetil | last post by:
Hello, I am not sure whether I have asked this before but I havent resolved his issue yet. any kind of quick help will be appreciated. Requirement: To get the value of a field from a table on...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.