0

I have a search that displays results. The results are of two types Items and Contacts. They are displayed under one template in a ListView using .Union(). I have two pages ContactDetails.aspx and ItemDetails.aspx.

Below is a example of my <ItemTemplate>. This just shows the Contact part. How would I change those links based on whether it is a Item or Contact and change the URL based on that?

This is the URL I would need to use for Items ~/LoggedIn/ItemDetails.aspx?ItemID={0}

              <ItemTemplate>
                        <asp:HyperLink runat="server" ID="link"
                        Text='<%#Eval("Name") %>'
                       NavigateUrl='<%#Eval("ID", "~/LoggedIn/ContactDetails.aspx?ContactID={0}")                             %>' />
                    <br />

                    <ul>

                        <li>
                            <span><b>Identity:</b><%#Eval("ID") %></span></li>


                        <li><span><b>Phone:</b><%#Eval("Phone") %></span></li>

                    </ul>

                                    <asp:HyperLink runat="server" CssClass="btn"  ID="ConUpdateLink"
                        Text='Update'
                        NavigateUrl='<%#Eval("ID", "~/Admin/UpdateContact.aspx?ContactID={0}") %>' />                        

                </ItemTemplate>

Hope this makes sense.

5
  • @ean5533 How would I change those links based on whether it is a Item or Contact and change the URL based on that. Commented Dec 11, 2012 at 16:16
  • @jackncoke: Basically I can see two links on your code. What you expect? do you need to pass somthing along with the contactId?? Commented Dec 11, 2012 at 16:19
  • @huMptyduMpty ContactID and ItemID become ID when they are displayed in the listview template. Now that they are one in the same i am having a issue of directing them to proper details page. My Details pages grab the querystring. So i guess what i am trying to expect is that when i click on a item it goes to ItemDetails and when i click on a Contact it goes to ContactDetails. Commented Dec 11, 2012 at 16:26
  • @jackncoke: How you determine whether its a itemid or contactid ?? Commented Dec 11, 2012 at 16:29
  • @huMptyduMpty That was the heart of the question! Sorry for poor explanations. Commented Dec 11, 2012 at 16:32

1 Answer 1

1

change it:

    <asp:HyperLink runat="server" CssClass="btn"  ID="ConUpdateLink"
        Text='Update' 
        NavigateUrl='<%# GetValidUrl((string)Eval("ID")) %>' />

Then in the code behind:

    public string GetValidUrl(string id)
    {
        string ret = string.Empty;
        if (/*it is item id*/)
        {
            ret = string.Format("~/Admin/UpdateContact.aspx?ContactID={0}", id);
        }
        else if (/*it is contact id*/)
        {
            ret = string.Format("~/LoggedIn/ItemDetails.aspx?ItemID={0}", id);
        }
        return ret;
    }

you need to add the part for checking types by id, or pass other value that can be used for this purpose.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.