Reputation: 11588
i think this maybe an easy one...
I have a Gridview, bound to a dataSource with this query:
select userid, name, phone from users
I need to change the content of the Name cell to a link, like so:
<a href="http://www.domain.com/page.aspx?userid=12345">User's Name</a>
so OnRowDataBound i'm doing this:
e.Row.Cells[1].Text = "<a href=\"http://www.domain.com/page.aspx?userid=\" + e.Row.Cell[0].Text + "\">" + e.Row.Cells[1].Text + "</a>";
It all works fine this way. My problem is that i don't want to display the UserId column in the Gridview, but when i attribute it (asp attribute or server-side) Visible="false"
to the BoundField UserId, i can't capture it's value to build the Name Cell.
Thanx for your help
Upvotes: 2
Views: 126
Reputation: 14864
Make your gridView to use template items instead of simple grivdiew column.
<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName")%>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
You can find a nice intro Here
Upvotes: 4
Reputation: 2134
Agree with Jani, this should be done with a template field. If you really need to do it the other way, see Can data be kept in a dynamically bound GridView's invisible fields?.
Upvotes: 0