I want to have a gridview where the first field is a link to a page like mypage.aspx?selectedName=John if john row is selected or mypage.aspx?selectedName=Jim if Jim row is selected. How can I create the link for each row?
Asked
Active
Viewed 1,960 times
1 Answers
2
Use a TemplateField
to custom style a column.
<Columns>
... your other columns ...
<asp:TemplateField HeaderText="Link">
<ItemTemplate>
<a href='<%# "mypage.aspx?selectedName=" + Eval("Name") %>'>Click me</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
Where Name
is the name of the field that contains the name of the person.

Jan Jongboom
- 26,598
- 9
- 83
- 120
-
is there any way I can encode the value Eval("Name") gives me? – Ryan Feb 16 '11 at 17:29
-
Yes, by wrapping it into `HttpUtility.HtmlEncode()` – Jan Jongboom Feb 17 '11 at 09:59