Forum Moderators: open

Message Too Old, No Replies

Datagrid Image as Link

         

Argblat

5:04 pm on Dec 16, 2005 (gmt 0)

10+ Year Member



Hi all,

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

TheNige

8:16 pm on Dec 16, 2005 (gmt 0)

10+ Year Member



For the template column just do the following:

<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.

Argblat

3:04 pm on Dec 19, 2005 (gmt 0)

10+ Year Member



Nige, thank you for the response.

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

TheNige

8:06 pm on Dec 20, 2005 (gmt 0)

10+ Year Member



Using DataBinder.Eval or just the Container.DataItem may depend on the type of datasource you are using. For reference what were you using as the datasource? Datareader, dataset, arraylist?

Argblat

4:57 pm on Dec 21, 2005 (gmt 0)

10+ Year Member



The DataGrid in this example is bound to a DataSet which is being populated via MS Sql Server 2000

-Mike