Create Dynamic Radio Button List Using XML

Posted on 2006-04-21
Medium Priority
Last Modified: 2010-04-23
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)


Question by:janmarini

Author Comment

ID: 16527414

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

Accepted Solution

GranMod earned 0 total points
ID: 16529188
Closed, 500 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question