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

VB-WEB: Adding column to radiobuttonlist

I have a radiobuttonlist bound to a dataset on the Page Load event, it has about 150 items. I used two columns from my SQL Server database, ItemVal for the DataValue field and ItemText for the DataText field. However my database has a third column which includes a comment (nvarchar(50)) field, ItemComment. I would like this to appear next to the given text in the radiobuttonlist as a separate column. I would like the column to be either an asp:label,text or literal so based on other conditions I could display or hide it.

Although I need this for something different, I could see a very practical need for this by having a textbox in line with a radiobutton item text of "Other" where the user would need to populate what the other is and was suprised that I could find nothing in my many searches.

Thanks to the one who knows,
TJ
Jun 13 '07 #1
2 1732
nateraaaa
663 Expert 512MB
I have a radiobuttonlist bound to a dataset on the Page Load event, it has about 150 items. I used two columns from my SQL Server database, ItemVal for the DataValue field and ItemText for the DataText field. However my database has a third column which includes a comment (nvarchar(50)) field, ItemComment. I would like this to appear next to the given text in the radiobuttonlist as a separate column. I would like the column to be either an asp:label,text or literal so based on other conditions I could display or hide it.

Although I need this for something different, I could see a very practical need for this by having a textbox in line with a radiobutton item text of "Other" where the user would need to populate what the other is and was suprised that I could find nothing in my many searches.

Thanks to the one who knows,
TJ
I am not quite sure why you have so many radiobuttons displaying on a page. I tried recreating your situation and it is a hassle to scroll that far to find what you want but that is your choice. As far as adding a column I have found a way to add text to the right of your radiobuttonlist text. You will need to do the following.

Expand|Select|Wrap|Line Numbers
  1. RadioButtonList2.DataSource = datasetname;
  2. RadioButtonList2.DataTextField = "ItemText ";
  3. RadioButtonList2.DataValueField = "ItemVal ";
  4. RadioButtonList2.DataBind();
  5.  
  6. int i = 0;
  7. foreach(ListItem item in RadioButtonList2.Items)
  8. {
  9. item.Text = item.ToString() + " " + datasetname.Tables[0].Rows[i]["ItemComment"].ToString();
  10. i ++;
  11. }

You can add as many spaces between the text as you would like. In my example I only added one space.

Good Luck

Nathan
Jun 13 '07 #2
Nathan,

Even though I had a situation that seemed impractical with many radio list items, I still believe this is a very practical need to get textboxes or other text in-line with radio button items.

Your solution puts me on the right track as I will need some sort of loop, but your solution merely joins my text. I can do the same and avoid by the loop concatenating "ItemText" with "ItemComment" in the SQL command or in the second line..

RadioButtonList2.DataTextField = "ItemText " & " " & "ItemComment"

However, I am trying to get a separate object like a textbox, literal control or label to appear in-line next to each RadioButton List item. My attempt falls apart at the ???<asp:label spot below as I don't know what to place there or reference since I cannot just add a label in the form portion within the radiobuttonlist especially when the radiobutton is built using the DataBind(). I did need this in VB and modified your code as

RadioButtonList2.DataSource = datasetname
RadioButtonList2.DataTextField = "ItemText "
RadioButtonList2.DataValueField = "ItemVal "
RadioButtonList2.DataBind()

dim i as integer = 0
For each ListItem item in RadioButtonList2.Items
item.Text = item.ToString() + &nbsp; + ???<asp:label text=datasetname.Tables(0).Rows(i).("ItemComment") .ToString() />???
Next
Jun 13 '07 #3

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

Similar topics

16
by: Terry | last post by:
Hi, I need some feedback. We are converting to .Net and we are trying to decide on whether to use VB.net or C#.net. As far as our current systems, they will probably be rewritten in ASP.Net. I...
13
by: Arsalan | last post by:
Is there any advantage in C# over VB.NET ? Or the difference is only syntax ? Can anything done in C# which cannot be done in VB.NET?
28
by: Andy | last post by:
Any good resources regarding benefitis by using C3 over VB? /Andy
12
by: Leo Muller | last post by:
I always thought that moving from VB.NET to C# would be very easy. Even though so far it hasn't been hard, there are some annoying things, that may have to do with my visual studio settings. -...
16
by: Ben Hannon | last post by:
Hi, I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of the VB6 hassles with cloning and serializing an object). All my classes I need cloneable/serializable are now in a...
182
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
25
by: Sharrukin Amiri | last post by:
Hello, I am using VB 6.0 for many years. Everytime I needed to build software applications, I just opened VB 6.0 and started coding. I am now looking VB.NET Express Edition and I find I can no...
2
by: D H | last post by:
Hi, Hi, I was looking for your opinion on VB.NET - its long-term prospects, etc. Sorry this is vague, but it's not meant to be a troll. It's a pro-VB.NET post actually. I haven't used VB or...
19
by: lonelyplanet | last post by:
Hi, I'm studying for 70-306 using the book "MCAD/MCSD Visual Basic .NET Windows Applications" published by McGraw Hill (ISBN: 0-07-212583-7). I found the book has no programming exercise...
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...
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.