title: Dynamically create and access RadioButtonLists from code-behind
body: <p>My problem is: I have a stripped down <code>default.aspx</code> page. Aside from a  element, almost ALL the functionality has to be in the code-behind in <code>aspx.vb</code>.</p>
  
  <p>The program retreives information from a database and compares this to another list of tables, number of both lists can vary.</p>
  
  <p>So I need to "bind" a dynamic number of RadioButtonLists to the <code>asp:table</code> element controls, and I need to create a dynamic number of ListItems to each RadioButtonList created. Later, I need to be able to access the selected value of each in order to decide future functions in the database.</p>
  
  <p>An example of the code is like this:</p>
  
  <p><strong><em>aspx file:</em></strong></p>
  
  <pre><code>&lt;asp:table ID="table1" runat="server"&gt;
  </code></pre>
  
  <p><hr/>
  <strong><em>aspx.vb file (code-behind):</em></strong></p>
  
  <pre><code>Sub createHtmlTables()
  
      For i = 0 To productIndex.Count - 1
  
          ''//create a RadioButtonList for each i
          Dim row As New TableRow
          Dim cell As New TableCell
  
          For k = 0 To productTypeAmountIndex.Count - 1
  
              ''//create a ListItem(radiobutton)
              ''//for each k and include it in the RadioButtonList
  
              ''//assign a value (for example name) of the product as
              ''//the ListItems ID to retreive it later
  
          Next
  
          ''//add the RadioButtonList to cell.controls etc
          Table1.Rows.Add(row)
  
      Next
  End Sub
  
  Sub addToDb()
      For i = 0 To productIndex.Count - 1
          ''//get the RadioButtonList for each i
          ''//and return the value of the selected radiobutton
          ''//within the list to a variable
  
      Next
  
  End Sub
  </code></pre>
  
  <p>Sorry if this is long and confusing, but as I can't even form my questions right yet, I tried to include as much information as possible. Basically I just need an example of how and which methods to use to get all that working.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Everyone keeps telling me that going for tables to begin with was a mistake, but some place I found claimed that you can't customize datagrid looks as easily as you can with tables. I guess I'll start the whole thing from scratch then.</p>
  
  <p>Thing is that the UI should be as graphically pleasing as possible, with the tables I can do all sorts of neat things such as colouring the cells according to the information inside etc.</p>
  
  <p>Anyway, thanks but not what I was looking for but I'll try to remake the thing with datagrid / gridview and see what happens. Might take a few days before I learn enough of them to use them and get back here.</p>