Forum Moderators: open
I would like to create a column within a DataGrid (bound to a DataSet coming from a SQL Server Query) where each row is the same image, the image is a link, and the link contains a dynamic query string
Here is my dilemna. If I chose to make the column of type HyperLink I can create repeating text that has a dynamic query string based on the ID for that row...but I can't figure out how to replace the text with an image
<asp:HyperLinkColumn Text="Details" DataNavigateUrlField="EMPLOYEE_ID" DataNavigateUrlFormatString="Details.aspx?id={0}" HeaderText="Details"></asp:HyperLinkColumn>
If I chose to make the column a Template I can make it the image I want and I can make it a hyperlink, but I can't figure out how to add the dynamic querystring part
<asp:TemplateColumn HeaderText="Details"><ItemTemplate><div align='center'><a href="WebForm1.aspx?id={0}"><img alt="" src="images/magnify.gif" style="border: 0;"></a></div>
</ItemTemplate></asp:TemplateColumn>
Can someone tell me how to EITHER add an image to a HyperLink column OR add a dynamic querystring to a Template Column (the Template equivalent of DataNavigateUrlField so I can do something like?id={0}
Thank you in advance!
-Mike
<asp:TemplateColumn HeaderText="Details">
<ItemTemplate>
<div align='center'>
<a href='WebForm1.aspx?id=<%# Container.DataItem("MyDataBaseColumn") %>'>
<img alt="" src="images/magnify.gif" style="border: 0;">
</a>
</div>
</ItemTemplate>
</asp:TemplateColumn>
Be sure to use single quotes around your databind tags in the URL though or it will throw an error.
Just to close out this topic for future reference ... your suggested solution gave me an error BUT was crucial in pointing me towards one that did work using <%# DataBinder.Eval(Container.DataItem, "DB Column Name")%>
<asp:TemplateColumn HeaderText="Details">
<ItemTemplate>
<div align='center'>
<a href='Details.aspx?id=<%# DataBinder.Eval(Container.DataItem, "employee_id")%>'><img alt="" src="images/magnify.gif" style="border: 0;"></a>
</div>
</ItemTemplate>
</asp:TemplateColumn>
Thank for the help,
Mike