NavigateUrl passing parameters

M

MikeD

Hello,

I wish to use a Hyperlink control within a repeater but am having trouble
forming the tag. The NavigateURL part is causing the most trouble. I wish to
form a link of the format article.aspx?ArticleNum=2 with the actual number
being pulled from a dataset. Here's what I have so far:

<asp:Hyperlink id="hypTitle" runat="server" NavigateUrl='<%#
"article.aspx?ArticleNum=" + DataBinder.Eval(Container.DataItem, "ID")%>'>
<%# DataBinder.Eval(Container.DataItem,"strTitle")%>
</asp:Hyperlink>

If I remove the text string from the NavigateURL element then the page will
display, but with it it it errors stating "System.FormatException: Input
string was not in a correct format.". It seems to be trying to convert the
string element to a double type according to the stack trace.

Is there an obvoius problem with my code or a better way of doing this?

Any thoughts appreciated.

<M>ike
 
C

CMA

try this

<asp:Hyperlink id="hypTitle" runat="server"
NavigateUrl='article.aspx?ArticleNum=<%#
DataBinder.Eval(Container.DataItem, "ID").ToString() %>'>
<%# DataBinder.Eval(Container.DataItem,"strTitle").ToString() %>
</asp:Hyperlink>
 
M

MikeD

That helps partially,

It forms most of the link correctly, but in place of the integer identifying
the article number it places the string <%#
DataBinder.Eval(Container.DataItem, "ID").ToString() %>, so when the link is
followed it fails. Does this part of the expression need to be identified
separately so it binds before the expression is formed?

Cheers,

<M>ike
 
M

MikeD

Success!

With a bit of fiddeling I can up with this code which seems to work:

<asp:Hyperlink id="hypTitle" runat="server"
NavigateURL='<%# "article.aspx?ArticleNum=" &
DataBinder.Eval(Container.DataItem, "ID")%>'>
<%# DataBinder.Eval(Container.DataItem, "ID")%>
</asp:HyperLink>

Thanks for your input.

<M>ike
 
C

CMA

oopps.. bcos i was given the solution in C# :)) so u had to change it to
VB.. right? whenever u post a message dont forget to specify the language or
u have to just change the code to ur language. i'm very sorry, i couldnt
mention the language too... anyway, u got the solution. isn't it? u just
needed to "+" >> "&".

Regards,
CMA.
 
M

MikeD

You're right I should have mentioned the language (sorry!). Thanks for your
thoughts though as they lead me to a working solution.

<M>ike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top