Question

I'm coding an application with JQuery Mobile and ASP.NET. I have a page with this code:

<asp:ListView ID="accountsListView" runat="server" DataSourceID="XmlDataSource1">
    <LayoutTemplate>
        <div id="itemPlaceHolderContainer" runat="server">
            <ul data-role='listview' data-theme='c' data-inset='true'>
                <span id="ItemPlaceHolder" runat="server" />
            </ul>
        </div>
    </LayoutTemplate>
    <ItemTemplate>

        <li>
            <a href='Account_Details.aspx'><h1><%#XPath("name")%></h1>
            <p><%#XPath("location")%></p> 
            </a>
        </li>

    </ItemTemplate>
</asp:ListView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" 
    DataFile="~/accountlist.xml"></asp:XmlDataSource>

This creates a list from my xml file of accounts. I want to have the user select an account and have the page send the node path to another page so I can display all information about the individual account. I'm kind of stuck on how exactly I should go about doing this.

A sample of the xml file is this:

<?xml version="1.0" encoding="ISO-8859-1"?>
 <AccountsList>
     <account>
      <name>Bubba Gump Shrimp Co.</name>
      <location>Alabama</location>
      <account_num>1986</account_num>
      <contact_name>Forrest Gump</contact_name>
      <contact_phone>555-555-5555</contact_phone>
     </account>
 </AccountsList>
Was it helpful?

Solution

Just make an onclick handler and have that pass whatever data you want in a query parameter (or json data if you want). You may wish to style your div appropriately to make it look like a normal a tag.

 // skip the XML if you want and just use inline C# or vb
 <div id='blank-link' onclick='handleClick(" <%= myAccountId %> "'><%= myAccountName %></div>

 function handleClick( id ){        
    window.location.href = "MyAspPage.aspx?id=" + id;
 }

If you don't want to use query parameters, you should look into ASP.NET URL routing to parse out values by using just accounts/id etc. http://msdn.microsoft.com/en-us/library/cc668201.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top