luca.p.alexandru
luca.p.alexandru

Reputation: 1750

Binding data to Template Field in Asp.net

I want to bind data to a templatefield in asp.net. I know you do this with the following code

Text = '<%#Bind("ColumnName") %>'

Where Text is the Text Property of the control I want to bind it to. However I want to bind a another thing to my text in the control, I want to bind to a Hyperlink's NavigateUrl the following:

"Default.aspx?id=" 

and bind this to and id from a database. How can I achieve this? Thank you.

Upvotes: 1

Views: 1314

Answers (3)

Nilesh Thakkar
Nilesh Thakkar

Reputation: 2895

You could have something like below:

NavigateUrl='<%# "Default.aspx?id=" +Eval("id") %>' 

Upvotes: 1

Raghubar
Raghubar

Reputation: 2788

Try This.

 <asp:HyperLink ID="HyperLink1" NavigateUrl='<%# "~/Default.aspx?id=" + Eval("something") %>' runat="server">HyperLink</asp:HyperLink>

Upvotes: 1

Tim Schmelter
Tim Schmelter

Reputation: 460148

Perhaps:

NavigateUrl='<%# String.Format("Default.aspx?id={0}&nextParam={1}", Eval("ID"), Eval("NextColumn")) %>'

Upvotes: 2

Related Questions