Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 30th, 2007, 04:03 PM
Authorized User
 
Join Date: Feb 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Opening a customized page

Ok, I am having a tough time understanding how to do this. I have a series of names that I pull from a database and then display as hyperlinks.

When a user clicks on a name I want to be able to open a detailed page with that "names" information. I've read about PostBackURL but is does not seem to work with a hyperlink. Is there a specific control that I need to use?

Thanks for the help

 
Old March 31st, 2007, 04:03 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What do you have so far?

Usually this is just done with hyperlinks to the details page that define a userid on it in the query string. Then you get the id from the query string over on the detail page and serve up whatever details you want to show. Just look at the user names next to the posts in this thread... your's comes up as this: http://p2p.wrox.com/pop_profile.asp?...splay&id=58645


-Peter
 
Old March 31st, 2007, 08:37 PM
Authorized User
 
Join Date: Feb 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok here is what I am trying to do: I have generated a datalist of Company Names that appear as hyperlinks, then when the user clicks on a company link the client's page should open up. I am trying to tailor the navigate URL to include the PKClient for the look up but I keep getting the following error: Overload resolution failed because no accessible 'Eval' accepts this number of arguments.


Here is the code that I am trying to use:
<ItemTemplate>
                <asp:HyperLink ID="ClientName" runat="server" Text='<%# Eval("ClientName") %>' NavigateUrl='<%# Eval("PKClient", "ClientSummary.aspx?PKClient={0}" %>'></asp:HyperLink>
            </ItemTemplate>

Thanks for the help
 
Old March 31st, 2007, 08:58 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Eval is meant to reference a column in the datasource, it only takes one argument: the column name.

This is not valid
<%# Eval("PKClient", "ClientSummary.aspx?PKClient={0}" %>

I might suggest adding a column to your datasource that contains the necessary link.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 31st, 2007, 09:30 PM
Authorized User
 
Join Date: Feb 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My datasource does contain the PKClient.

"SELECT Client.ClientName, Client.PKClient FROM Client"

I think the issue is with how to build the navigate url to contain the PKClient.

This code attempts to open a page with the URL of "PKClient" and works. Although, the URL only contains the PKClient and not the page reference.
<ItemTemplate>
                <asp:HyperLink ID="ClientNameLabel" runat="server" Text='<%# Eval("ClientName") %>' NavigateUrl='<%# Eval("PKClient") %>'>
                </asp:HyperLink><br />

I just can't get the URL to have both the base URL plus the changing PKClient

 
Old April 1st, 2007, 08:48 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

To get the url with the correct pk do something like this:

"SELECT Client.ClientName, 'ClientSummary.aspx?PKClient=' + Client.PKClient as URL FROM Client"

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old April 1st, 2007, 10:00 AM
Authorized User
 
Join Date: Feb 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, that did the trick.

 
Old April 1st, 2007, 10:09 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem, glad it worked out of your.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old April 1st, 2007, 10:53 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I hate to spoil the fun, but I wouldn't recommend doing this.

First of all, Eval *does* have an overload that allows you to format the expression: http://msdn2.microsoft.com/en-us/library/2d76z3ck.aspx

The DataBinder class has two overloads: one that accepts the object and a single string (the name of the property on the object) and another one that accepts an additional format expression.

Snuffles: the code you posted was, as Doug said, invalid. However, this isn't because Eval doesn't have an overload, but because you were missing a ):

NavigateUrl='<%# Eval("PKClient", "ClientSummary.aspx?PKClient={0}"%>'

should be

NavigateUrl='<%# Eval("PKClient", "ClientSummary.aspx?PKClient={0}")%>'

Notice the additional ) between the " and the %. You just forgot to close the call to Eval.

With the ) in place, your example will run fine.

Personally, I would never hard code the path in my select statement against the database. It makes it really hard to reuse the same code in a different scenario. It also makes it near impossible for others to find out why a certain page redirects to some location. Using the Format expression as you posted is, IMO, the best way to go.
As an alternative, you could have also used simple string concatenation:

NavigateUrl='<%# "ClientSummary.aspx?PKClient=" + Eval("PKClient") %>'>


Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a saved Outlook customized form Arsi BOOK: Professional Outlook 2007 Programming ISBN: 978-0-470-04994-5 3 January 11th, 2012 04:47 PM
Opening page layout... photon BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 October 7th, 2008 04:22 PM
Internet Page Opening eyuvaraj Beginning VB 6 6 August 22nd, 2006 08:42 AM
Error while opening an aspx page manchanahari ASP.NET 1.0 and 1.1 Basics 1 February 15th, 2006 09:43 AM
Customized error page for missing records karib Classic ASP Databases 13 March 23rd, 2004 12:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.