Solved

Setting NavigateURL value using data binding.

Posted on 2007-04-08
4
3,099 Views
Last Modified: 2012-08-14
I am trying to get the value of a database table column and use it to navigate to a different web page.  I am using the following syntax which works.  It redirects to the new page and passes the value of "refurl" but it does not pass the value of "Story_ID".  

<asp:HyperLink id="show_story" runat="server"
NavigateUrl='~/view_story.aspx?refurl=default.aspx&story=<%# DataBinder.Eval(Container.DataItem, "Story_ID") %>

On its own, <%# DataBinder.Eval(Container.DataItem, "Story_ID") %> returns the value stored in Story_ID.

I am trying to use this in a repeater control on a asp.net web page.
0
Comment
Question by:Mike_Stevens
  • 2
4 Comments
 
LVL 15

Expert Comment

by:igor_alpha
ID: 18873672
Hi Mike_Stevens,
In one of my projects I have same syntax of generating URL in repeater and everything work well.
Probably, you forgot to bind data to repeater?

Syntax must be such following:
Repeater1.DataSource = values;
Repeater1.DataBind();

If you use SqlDataSource or ObjectDataSource check out that it filling with values.
0
 
LVL 3

Accepted Solution

by:
viveksg earned 500 total points
ID: 18874530
Try this mate.

<asp:HyperLink ID="show_story" Runat="server" NavigateUrl='<%# "~/view_story.aspx?refurl=default.aspx&story=" + DataBinder.Eval(Container.DataItem, "Story_ID")%>'>Click Here</asp:HyperLink>
0
 

Author Comment

by:Mike_Stevens
ID: 18874968
Your code returns  "Conversion from string "~/view_story.aspx?refurl=default" to type 'Double' is not valid."

The "story ID" value is a numeric value.

0
 

Author Comment

by:Mike_Stevens
ID: 18874976
i converted the story ID value to a string and it works fine.   Thanks for the help

DataBinder.Eval(Container.DataItem, "Story_ID").tostring
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question