Web Analytics Made Easy -
StatCounter XML and ASP.NET data binding issues - CodingForum


No announcement yet.

XML and ASP.NET data binding issues

  • Filter
  • Time
  • Show
Clear All
new posts

  • XML and ASP.NET data binding issues

    Okay, so Im trying to bind data from an XML page to an ASP.Net page language VB. at first it displayed the first round of choices: ID codes, but not travel destinations, so I switched the values of the fields. Now nothing. I undid the change, but it still wont show anything but the label used for output. the goal was to bind the xml so the data appeared as radio buttons in the aspx page. According to all my resources, this should work but its not. Help please!
    Here is my code:
    First the XML:

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="basic.xsl" ?>
          <Destination>Tokyo, Japan</Destination>
          <Destination>New York, New York</Destination>
          <Destination>London, England</Destination>
          <Destination>Paris, France</Destination>
          <Destination>Hiroshima-Kyoto, Japan</Destination>
    Now the asp.net in vb:

    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data"  %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        Sub Page_Load()
            If Not Page.IsPostBack Then
                Dim myvacay = New DataSet
                rb.DataSource = myvacay
                rb.DataValueField = "Destination"
                rb.DataTextField = "TripID"
            End If
        End Sub
        Sub displayMessage(ByVal s As Object, ByVal e As EventArgs)
            lbl1.text = "You chose to go to: " & rb.SelectedItem.Text
        End Sub
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        End Sub
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <form id="form1" runat="server">
        <asp:RadioButtonList id="rb" runat="server"
    AutoPostBack="True" onSelectedIndexChanged="displayMessage"/>
        <asp:Label ID="lbl1" runat="server" Text="Label"></asp:Label>
    Last edited by vinyl-junkie; Apr 12, 2009, 07:23 PM. Reason: Added code tags
    pressure can turn a lump of coal into a flawless diamond, or an average person into a perfect basketcase.

  • #2
    I just tryed this in c# and it works fine. I am not up on VB but I see you have two page load events. One is a normal Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) the other looks like a sub that has to be called.

    Here is your code in c# it all works good. You can use a c# to vb converter C# to VB
     protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)
        protected void load_Vacation_xml()
            DataSet myvacay = new DataSet();
            myvacay.ReadXml(MapPath("App_Data\\Vacation.xml")); // I put the xml in my App_Data folder, just my preference.
            rb.DataSource = myvacay;
            rb.DataValueField = "TripID";
            rb.DataTextField = "Destination";
        protected void rb_SelectedIndexChanged(object sender, EventArgs e)
            Label1.Text = "You chose to go to: " + rb.SelectedItem;
    Last edited by Freon22; Apr 13, 2009, 10:48 AM.
    I was wondering why frisbees got bigger as they got closer, then it hit me.