Formatting DataGrid - Template column troubles
I have a DataGrid that's bound to a DataSet, and I'd like to make one of the columns a hyperlink. I have this in the page
Code:
<asp:TemplateColumn HeaderText="Agency">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Agency") %>'>
</asp:Label>
</ItemTemplate>
I thought I could just change to something like
Code:
<asp:Label runat="server" Text='<%# "<a href='Agencies.aspx'>" + DataBinder.Eval(Container, "DataItem.Agency") + "</a>" %>'>
but I guess it doesn't like that, getting an error - "The server tag is not well formed." I'm thinking I may need to use something like Chr(62) for the greater than sign (well, not quite as using C#), but is that the workaround? Or is there another way?
Thanks,
Mike
Re: Formatting DataGrid - Template column troubles
Urgh. This is ugly. So far I have this
Code:
<asp:Label runat="server" Text='<%# ((char)60).ToString() + "a href=" + ((char)39).ToString() + "Agency.aspx?a=" + DataBinder.Eval(Container, "DataItem.Agency") + ((char)39).ToString() + ((char)62).ToString() + DataBinder.Eval(Container, "DataItem.Agency") + ((char)60).ToString() + "/a" + ((char)62).ToString() %>'>
to come up with a string that ends up looking like
Code:
<a href='Agency.aspx?a=NM1234567'>NM1234567</a>
If anyone has any suggestions, it'd be appreciated.