Reputation: 15138
I have and oBjectDataSource which Gets my Information for my Grid View.
It shows all Information perfectly with this, automaticly generated:
<asp:BoundField DataField="Name" ItemStyle-Width="250px" HeaderText="Name" SortExpression="Name">
<ItemStyle Width="250px"></ItemStyle>
</asp:BoundField>
But I want to have an Hyperlink with the Field "Name" as Text and the field "UserID" as paramater in the navigateURL:
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" NavigateUrl="~/Test.asp?id='<%# Eval("userID") %>'" runat="server"><%# Eval("Name") %></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
I got an error here...
whats wrong?
Upvotes: 0
Views: 2871
Reputation: 537
Add this field within your gridview
In this example Id = ContentId
<asp:HyperLinkField DataNavigateUrlFields="ContentId" DataNavigateUrlFormatString="EditContent.aspx?ContentId={0}" Text="Edit" HeaderText="Edit" />
Upvotes: 0
Reputation: 1026
Try this. It seems like the problem was in using double quotes in Eval(“userID”) that conflicted with opening double quotes in NavigateUrl
<asp:HyperLink ID="HyperLink2" NavigateUrl='~/Test.asp?id=<%# Eval("userID") %>' runat="server"><%# Eval("Name") %></asp:HyperLink>
Upvotes: 0
Reputation: 26386
You can also achieve it this way - easier and simpler:
<asp:HyperlinkField DataTextField="Name"
DataNavigateUrlFormatString="~/Test.asp?id={0}"
DataNavigateUrlFields="userID"
/>
Upvotes: 1
Reputation: 9414
Try this:
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# "~/Test.asp?id="+Eval("userID") %>' Text='<%# Eval("Name") %>'></asp:HyperLink>
Upvotes: 2