Create Dynamic Radio Button List Using XML

I'm writing a web user control that contains 3 RadioButtonList web controls in addition to other controls.  

I would like to make this control reusable for different applications so instead of hard coding the radio buttons, I would like to dynamically add them when the form is loaded.  In addition to setting up the radio button item text, I would also like to associate a stored proc name that would be executed when the radio button is selected.  I was thinking that having this data in an external xml file would be the way to go since the xml file could be easily replaced/modified for other uses, and the user control would not need to be recompiled or redeployed.  

I am *really* new at using xml, so I am not sure of the best way to form it for this use.  It seems that each example I have found in my searches are all so different, that I am more confused than when I first started exploring this.  I would like to be able to use the xmlReader to create the radio buttons and gather the proc name.

Please let me know if you can add radio buttons to a RadioButtonList in this fashion, and how to get started on forming the XML.

I'm using Visual Studio 2002 - with VB code behind for the .ascx file.

Example Result:

RadioButtonList1 (can have up to 12 items)
  Map       (calls sp_Map)
  Class     (calls sp_class)
  Owner   (calls sp_owner)
  Street    (calls sp_street)
  Location (calls sp_Location)

RadioButtonList2 (can have up to 8 items)
  Vacant   (calls sp_vacant)


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

janmariniAuthor Commented:

Figured this out ....

XML looks something like this:

<?xml version="1.0" encoding="utf-8" ?>
      <!-- START OF: RadioButtonList1 name rbl1 max 12 values -->
            <desc>Land Use Code</desc>
      <!-- END OF: RadioButtonList1 name rbl1 -->
      <!-- START OF: RadioButtonList2 name rbl2 max 8 values -->
            <desc>Vacant Properties</desc>
            <desc>Open Permits</desc>
      <!-- END OF: RadioButtonList2 name rbl2 -->
      <!-- START OF: RadioButtonList3 name rbl3 max 4 values-->
      <!-- END OF: RadioButtonList3 name rbl3 -->

And Code looks like this:


'Populate dynamic RadioButtonLists using psRadioButtonsList.xml
        If Not Page.IsPostBack Then
        End If

Private Sub PopulateLists()
        'Create dynamic RadioButtonLists from XML file
        'Schema column (0)=Value (1)=Desc (2)=Storedd Proc Name
        'Assumes DataSet.Table is created for each ListBox (3)
        'If Table is empty set RadioButtonList.visible = False
        'Dim ds As DataSet = New DataSet()
        Dim t As DataTable
        Dim r As DataRow
        Dim c As DataColumn
        Dim a
        For Each t In ds.Tables
            'a = "TableName: " + t.TableName
            Select Case t.TableName
                Case "rbl1"
                    For Each r In t.Rows
                        If r(0).ToString() <> "" Then
                            rbl1.Visible = False
                            Exit For
                        End If
                    Next r
                Case "rbl2"
                    For Each r In t.Rows
                        If r(0).ToString() <> "" Then
                            rbl2.Visible = False
                            Exit For
                        End If
                    Next r
                Case "rbl3"
                    For Each r In t.Rows
                        If r(0).ToString() <> "" Then
                            rbl3.Visible = False
                            Exit For
                        End If
                    Next r
            End Select
        Next t
    End Sub

Example to obtain Vlaue and Stored Proc Name when item is selected in RadioButtonList

Private Sub rbl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbl1.SelectedIndexChanged
        If rbl1.SelectedIndex = -1 Then
            col1 = rbl1.SelectedItem.Value
            Dim strProcName As String = ""

            Dim drv1 As DataRowView
            Dim dataview1 As New DataView()
            dataview1.Table = ds.Tables("rbl1")
            dataview1.RowFilter = "[desc] = '" & Trim(col1) & "'"

            For Each drv1 In dataview1
                'Save value as session variable needed for later processing in session
                Session("col1") = drv1("value")
                strProcName = drv1("proc")
      End If
End Sub
Closed, 500 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.