Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i use labels with arrays in asp.net vb code behind

Status
Not open for further replies.

afybim

Technical User
Nov 13, 2002
16
TR
Hello,
I have to use some codes as follows:

...
For i = 1 To 21
Label(i).text = ds.Tables(0).Rows(0)(1)
RadioButtonList(i).SelectedItem.Text = ds.Tables(0).Rows(0)(2)

Next
....

how can i use label or radiobuttonlist controls with arrays in asp.net vb codebehind?
could you help me?
 
Your approach could probably be reconsidered here.

What you may want to do instead of all the looping (which is a little complicated) is just to have an array (or some other source) of data then bind it to a list control like a DataList.

That way, you don't have to deal with the hassle of creating 21 table rows manually, or you don't have to deal with the state maintenance issues of dynamically created controls (if you're creating the table rows dynamically).
 
I want to explain something about what i want to do.
I am making a test-quiz projects for students.There is a lot of questions and choices in the database.I want to relate with questions to labels and choices to radiobuttonlists items.

label1.text =question1
radiobuttonlist1.item(0).text=choice1
radiobuttonlist1.item(1).text=choice2
radiobuttonlist1.item(2).text=choice3
radiobuttonlist1.item(3).text=choice4

label2.text=question2
radiobuttonlist2.item(0).text=choice5
radiobuttonlist2.item(1).text=choice6
radiobuttonlist2.item(2).text=choice7
radiobuttonlist2.item(3).text=choice8
.
.
.
I want to do this in a loop and i have to use (i think) label(i).text,
radiobuttonlist(i).items(0).text vs.

How can i do this?


 
Rather than use a loop, use the method suggested by BoulderBum. You could simply use a DataReader and bind it to a RadioButtonList.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
afybim: BoulderBum & ca8msm are correct.

There is a lot of questions and choices in the database.

If the number of choices are always 4 for each Question, you can simply use one table - if there are alternatives to choose from (perhaps up to 8 per question, or even 12 - say you want to mix them up over time) create a one to many table with the Question in the Parent table and the various answers in the child table (using a key identifier (and if there are multiple answer sets, an additional identifying ID) to pull out certain sets, or just one set if that is all you have).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top