views:

2292

answers:

3

The answer I'm looking for could be simple, I'm pretty much a beginner in this. Problem is, I barely know the methods and parameters of the RadioButtonList class at all. So perhaps I should be using some other method? If so, please tell me.

Here's the situation: I have a stripped down default.aspx page. Aside from a element, almost ALL the functionality has to be in the code-behind in aspx.vb.

The program retreives information from a database, the number of which may vary, it compares this to another list of tables the number of which can also vary.

So I need to "bind" a dynamic number of RadioButtonLists to the asp:table 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.

An example of the code is like this:

In .aspx:

<asp:table ID="table1" runat="server">


In .aspx.vb (code-behind)

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

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. Thank you.

A: 

Rather than a table, you'll have better luck with a true server control like gridview or datagrid, or repeater. Then you can just wire up the datasource property on your control.

For all dynamic controls, remember that you have to recreate them every time you do a postback. This may sound odd, but the trick is the every request to the server, including postbacks, uses a different instance of your page class. When that request/postback finishes the page instance used for that request is destroyed. The only things left active are the session and the cache.

Joel Coehoorn
A: 

Yeah I get that alot. :) 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.

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.

Anyway, thx. 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.

you can do conditional formatting on datagrid cells. See http://www.codeproject.com/KB/webforms/gridcolumnformatting.aspx
paulwhit
A: 

Did anyone ever find an answer to Tauron question? I have the same problem and I have tried dataGrids, Repeaters, and datalist with the same results. The value returned is always false. So I'm unable to determine which items were selected by the end-user after the asp form element was dynamically created based on a user query against an SQL DB.

Any help would be greatly appreciated.

Reply to [email protected]