Creating dynamic radiobuttonlist from datatable in vb.net
Posted on 2007-07-23
Hi guys, I need help with creating a dynamic radiobuttonlist. There is a radiobuttonlist that sits as an empty control. I am creating a datatable from a stored procedure, and then looping through the rows adding a new radiobutton with each passthrough. This works fine, no problems. The only thing is the actual value of each radiobutton is the actual text of the question that is getting populated. Here is the current population code :
Dim i As Integer
For i = 0 To dt.Rows.Count - 1
Dim dr As DataRow = dt.Rows(i)
Now what I need to do differently is this. I need to generate this radiobuittonlist dynamically, making the text of the radio button choice this : dr.Item("LongQuestionText"). I also need to make the value of the radiobutton this : dr.Item("PortalOfferID"). How can I do this?
To clarify if the "LongQuestionText" is "What is my name?" Then I get a radio button that looks like this in code : <input id="rdlQuestions_0" type="radio" name="rdlQuestions" value="What is my name?"/><label for="rdlQuestions_0">IWhat is my name?</label>. I need to somehow tie that PortalOfferID to the radiobutton so that I can write code against it.