?
Solved

Create Dynamic Radio Button List Using XML

Posted on 2006-04-21
2
Medium Priority
?
187 Views
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)

etc.

Thanks!
0
Comment
Question by:janmarini
2 Comments
 
LVL 7

Author Comment

by:janmarini
ID: 16527414

Figured this out ....

XML looks something like this:

<?xml version="1.0" encoding="utf-8" ?>
<RadioButtonLists>
      <!-- START OF: RadioButtonList1 name rbl1 max 12 values -->
      <rbl1>
            <value>CLASS</value>
            <desc>Class</desc>
            <proc>ps_ListCLASS</proc>
      </rbl1>
      <rbl1>
            <value>LUC</value>
            <desc>Land Use Code</desc>
            <proc>ps_ListLUC</proc>
      </rbl1>
      <rbl1>
            <value>MAP</value>
            <desc>Map</desc>
            <proc>ps_ListMAP</proc>
      </rbl1>
      <!-- END OF: RadioButtonList1 name rbl1 -->
      <!-- START OF: RadioButtonList2 name rbl2 max 8 values -->
      <rbl2>
            <value>IMPROVED</value>
            <desc>ImprovedProperties</desc>
            <proc>ps_Test</proc>
      </rbl2>
      <rbl2>
            <value>VACANT</value>
            <desc>Vacant Properties</desc>
            <proc>ps_Test</proc>
      </rbl2>
      <rbl2>
            <value>OPEN</value>
            <desc>Open Permits</desc>
            <proc>ps_Test</proc>
      </rbl2>
      <!-- END OF: RadioButtonList2 name rbl2 -->
      <!-- START OF: RadioButtonList3 name rbl3 max 4 values-->
      <rbl3>
            <value></value>
            <desc></desc>
            <proc></proc>
      </rbl3>
      <!-- END OF: RadioButtonList3 name rbl3 -->
</RadioButtonLists>

And Code looks like this:

Page_Load......

'Populate dynamic RadioButtonLists using psRadioButtonsList.xml
'---------------------------------------------------------------------------
        If Not Page.IsPostBack Then
            PopulateLists()
        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()
        ds.ReadXml(Server.MapPath("psRadioButtonLists.xml"))
        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"
                    rbl1.Items.Clear()
                    For Each r In t.Rows
                        If r(0).ToString() <> "" Then
                            rbl1.Items.Add(r(1).ToString())
                        Else
                            rbl1.Visible = False
                            Exit For
                        End If
                    Next r
                Case "rbl2"
                    rbl2.Items.Clear()
                    For Each r In t.Rows
                        If r(0).ToString() <> "" Then
                            rbl2.Items.Add(r(1).ToString())
                        Else
                            rbl2.Visible = False
                            Exit For
                        End If
                    Next r
                Case "rbl3"
                    rbl3.Items.Clear()
                    For Each r In t.Rows
                        If r(0).ToString() <> "" Then
                            rbl3.Items.Add(r(1).ToString())
                        Else
                            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
        Else
            Formatrbl1()
            col1 = rbl1.SelectedItem.Value
            Dim strProcName As String = ""

            ds.ReadXml(Server.MapPath("psRadioButtonLists.xml"))
            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")
            Next
            getDataForList("strProcName")
      End If
End Sub
0
 

Accepted Solution

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

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