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

Create control at runtime

Can anyone please point me in the right direction. I want to create some
simple controls (radio buttons) at runtime. The problem is that I don't know
how many radio buttons I need or where they go until I read the database at
runtime.

Thanks
Nov 19 '05 #1
2 1337
Tom:
here's a fictious example:

Dim options As New RadioButtonList
For Each row As DataRow In ds.Tables(0).Rows
Dim item As New ListItem
item.Text = CStr(row("Name"))
item.Value = CStr(row("Id"))
options.Items.Add(item)
Next
Dim parent As String = CStr(ds.Tables(1).Rows(0)("Parent"))
Select Case parent
Case "sideNav"
columnSidenav.Controls.Add(options)
Case "footer"
footerCoontainer.Controls.add(options)
Case Else
paceholderDefault.Controls.add(options)
End Select

98% chance you can get rid of the entire for each loop and replace it with a
databind expression:

Dim options As New RadioButtonList
options.DataSource = ds.Tables(0)
options.DataTextField = "name"
options.DataValueField = "id"
options.DataBind()

the select case parent was just to show how you can add the radiobutton to
different containers at runtime..

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Tom Jackson" <tj************@home.com> wrote in message
news:Ox**************@TK2MSFTNGP15.phx.gbl...
Can anyone please point me in the right direction. I want to create some
simple controls (radio buttons) at runtime. The problem is that I don't know how many radio buttons I need or where they go until I read the database at runtime.

Thanks

Nov 19 '05 #2
Karl,

So fast!! I thought it would be more difficult! .Controls.Add was the key.

Thank you,

Tom
Nov 19 '05 #3

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

Similar topics

4
by: Tom Rathbun | last post by:
This is probably simple but it has stumped me. I want to create objects at runtime for example: A program that would allow you to draw lines on a form. For each new line I would like to create a...
5
by: Patrick Marti | last post by:
I wish to create some LinkButtons in DotNet. Because I will do it in dependence of the entries in a database, I can not add them with the mouse to the form as usually. I can create them in the...
0
by: ManjuG | last post by:
Hi, I have created an ActiveX control and build the project with 'No Common Language RunTime support' option and everything worked fine. But when I used the option 'Common Language Runtime Support...
3
by: leon | last post by:
hello friends, i am writing a page aspx and creating controls dinamicaly and then i must to create for each control the events as well. Anybody to know how????? happy day lion
3
by: RSB | last post by:
Hi Every one Having tuff time creating web controls Dynamically. All i am trying to do is read a table and generate a list of ASP TEXT Box. So how do i create this Control dynamically and where...
15
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
0
by: Eric | last post by:
Hi I want to know if it's possible to create a control at runtime in a different process than the main form There is a fonction I try but I have a message that tell me I can create control on...
3
by: JohnR | last post by:
I have a form with a number of text boxes, comboboxes etc. What I would like to do is create an event handler for the "mouseenter" event for each of the controls whereby I display information...
6
by: shapper | last post by:
Hello, How to create a CSS StyleSheet at runtime and added it an Asp:Label? I am using Asp.Net 2.0. Thanks, Miguel
1
by: amitsaxena1981 | last post by:
Hi, I am using asp.net with vb.net and creating the user control .My user control generate the table at runtime in which each column has button so i want to create the event handler for each run...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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...

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.