locked
Query string with xml in small jquery mobile app RRS feed

  • Question

  • User-1005115091 posted

    I have a datalist with and xml file that has a link in it that creates a query to another local file. Here's a sample of the xml:

    <item>

    <id>46</id>

    <cat>Management</cat>

    <image></image>

    <title>I'm Sorry I Broke Your Company</title>

    <summary>summary goes here</summary>

    <guid>http://www.someurl.net/mp3/BrokeCompany.mp3</guid>

    <pubDate>Fri, 6 Sep 2013 17:00:00 EST</pubDate>

    </item>

    This is the data list:

    <asp:DataList ID="DataList2" runat="server" DataSourceID="XmlDataSource1" CellPadding="4" ForeColor="#333333" Width="90%">

    <AlternatingItemStyle BackColor="White" ForeColor="#284775" />

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <ItemTemplate>

    <ul data-role="listview" data-inset="true">

    <li data-role="list-divider"><%#XPath("title")%></li>

    <i><%#XPath("subtitle")%></i>

    <a href ="<%#XPath("guid")%>" target="_blank">Listen</a>

    <a href ="podcasts.aspx?id=<%#XPath("id")%>" target="_blank">Listen</a>

    </ul>

    </ItemTemplate>

    <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

    </asp:DataList>

    <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/my.xml" XPath="podcasts/item[cat='Communication']"></asp:XmlDataSource>

    This is the page that accepts the query string:

    <asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource7" CellPadding="4" ForeColor="#333333" Width="90%">

    <AlternatingItemStyle BackColor="White" ForeColor="#284775" />

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <ItemTemplate>

    <h1><%#XPath("title")%></h1><br />

    <i><%#XPath("subtitle")%></i><br />

    <p><%#XPath("summary")%></p><br /><br />

    <a href ="<%#XPath("guid")%>" target="_blank">Listen</a>

    </ItemTemplate>

    <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

    </asp:DataList>

    <asp:XmlDataSource ID="XmlDataSource7" runat="server" DataFile="`/my.xml" ></asp:XmlDataSource>

    and this is the code behind:

    protected void Page_Load(object sender, EventArgs e)

    {

    if (Request["id"] != null)

    {

    String user_id = Request["id"];

    XmlDataSource7.XPath = String.Format(@"/podcasts/item[@id=""{0}""]", user_id);

    }

    }

    }

    When I use the query string the page always comes up blank, if I don't enter the ?id= part of the string I get all of the items.

    Can anyone suggest what I'm doing wrong?

    Saturday, August 15, 2015 4:57 PM

Answers

  • User61956409 posted

    Hi cucky1,

    Welcome to ASP.NET forum.

    If you’d like to pass variable via QueryString, the HTTP query string should be specified by the values following the question mark (?), like this:

    page1.aspx?txt=this is a query string test

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 17, 2015 5:07 AM
  • User61956409 posted

    Hi cucky1,

    <a href ="podcasts.aspx?id=<%#XPath("id")%>" target="_blank">Listen</a>

    Please try to modify your code to this.

    <a href ='podcasts.aspx?id=<%#XPath("id")%>' target="_blank">Listen</a>

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 26, 2015 3:56 AM

All replies

  • User61956409 posted

    Hi cucky1,

    Welcome to ASP.NET forum.

    If you’d like to pass variable via QueryString, the HTTP query string should be specified by the values following the question mark (?), like this:

    page1.aspx?txt=this is a query string test

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 17, 2015 5:07 AM
  • User-1005115091 posted

    Thanks for your response, but that is how it is set up already. When I click on they hyperlink I set up it creates a link "podcasts.aspx?id=1". But nothing shows up on the page. 

    Monday, August 17, 2015 9:03 AM
  • User61956409 posted

    Hi cucky1,

    <a href ="podcasts.aspx?id=<%#XPath("id")%>" target="_blank">Listen</a>

    Please try to modify your code to this.

    <a href ='podcasts.aspx?id=<%#XPath("id")%>' target="_blank">Listen</a>

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 26, 2015 3:56 AM