Special Hyperlink column in DataGrid

G

Guest

http://msdn.microsoft.com/library/d...webuiwebcontrolshyperlinkcolumnclasstopic.asp
works fine for a hyperlink column that contains one parameter in query string
only

<asp:HyperLinkColumn DataNavigateUrlField="id"
DataNavigateUrlFormatString="Maintenance.aspx?id={0}&process=1&admin=1"
DataTextField="name" SortExpression="id"
HeaderText="Name"></asp:HyperLinkColumn>

This will render a url like "<a href="Maintenance.aspx?id=123">someName</a>.
How can I enhance this to include the name (from another DB field) in the
parameter "<a href="Maintenance.aspx?id=123&name=someName">someName</a>.
 
W

W.G. Ryan eMVP

This should work for you if I understand the problem correctly. If not,
please let me know.


<ItemTemplate>
<asp:HyperLink runat="server" Text="View Details"
NavigateUrl='<%# "details.aspx?id=" & _
Container.DataItem("id") & _
"&someName=" & Container.DataItem("someName")
%>' />
</ItemTemplate>
</asp:TemplateColumn>

HTH,

Bill
 
G

Guest

For your case, it's better to rebuild link's NavigateUrl in
datagrid_ItemDataBound event:

ListItemType itemType = e.Item.ItemType;
if (itemType == ListItemType.Item || itemType ==
ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
HyperLink link = (HyperLink)e.Item.Cells[link_index].Controls[0];
link.NavigateUrl = "Maintenance.aspx?id=" + dv["NavigateUrl"] +
"&name=" + dv["name"];
}


HTH

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top