jump to navigation

Finding Template Column Controls December 08 2004

This may seem trivial but I have racked my brain on a few occasions when I take a break from programming.

Consider the following datagrid

<asp:datagrid id=”dgLogo” runat=”server”>
<column>
<asp:BoundColumn DataField=”filepath” HeaderText=”File Name”></asp:BoundColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Image ID=”imgLogo” Runat=”server” ></asp:Image>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp:datagrid>

Now suppose we want to find that image as the data is binding so we can associate an image URL based on the data in the specific row.

=== BEGIN CODE ===

For intDGIndex = 0 To dgLogo.Items.Count - 1
dgi = dgLogo.Items(intDGIndex)

‘ Get the image file name
strFileName = dgi.Cells(0).Text()

‘ Find the image control
imgThisLogoImage = dgi.FindControl(”imgLogo”)

If (Not (imgThisLogoImage Is Nothing)) Then
imgThisLogoImage.ImageUrl = Global.LogoURL & “” & strFileName
End If
Next
=== END CODE ===

The only problem with this currently is the need to specify a cell index rather than by data name. Hopefully this can be figured out some time soon!

Comments

Sorry comments are closed for this entry