I need to find the control "btnSort1" that is defined as follows
<asp:TemplateColumn Visible="False">
<HeaderTemplate>
Title
<asp:ImageButton id="btnSort1" runat="server" CommandName="sort" ImageUrl="../images/arrowdown.gif" CommandArgument="nvcTitle" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.nvcTitle") %>' ID="lblTitle"/>
</ItemTemplate>
</asp:TemplateColumn>
The code behind is:
Dim itm As DataGridItem
Dim ctrl As Control
For Each itm In grdFriends.Items
For Each ctrl In itm.Controls
If Not IsNothing(ctrl.FindControl("btnSort1")) Then
CType(ctrl.FindControl("btnSort1"), ImageButton).ImageUrl = "../images/arrowdownred.gif"
Else
Dim ctrl2 As Control
For Each ctrl2 In ctrl.Controls
If Not IsNothing(ctrl2.FindControl("btnSort1")) Then
CType(ctrl2, ImageButton).ImageUrl = "../images/arrowdownred.gif"
Else
Console.WriteLine(ctrl2.ID)
End If
Next
End If
Next
Next
the code doesn't break or crash but I can't find the item and instead I can find find lblTitle in the second loop ctrl2.control("lblTitle")
Can I search for a control that is stored in the header template? If yes, How?
<asp:TemplateColumn Visible="False">
<HeaderTemplate>
Title
<asp:ImageButton id="btnSort1" runat="server" CommandName="sort" ImageUrl="../images/arrowdown.gif" CommandArgument="nvcTitle" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.nvcTitle") %>' ID="lblTitle"/>
</ItemTemplate>
</asp:TemplateColumn>
The code behind is:
Dim itm As DataGridItem
Dim ctrl As Control
For Each itm In grdFriends.Items
For Each ctrl In itm.Controls
If Not IsNothing(ctrl.FindControl("btnSort1")) Then
CType(ctrl.FindControl("btnSort1"), ImageButton).ImageUrl = "../images/arrowdownred.gif"
Else
Dim ctrl2 As Control
For Each ctrl2 In ctrl.Controls
If Not IsNothing(ctrl2.FindControl("btnSort1")) Then
CType(ctrl2, ImageButton).ImageUrl = "../images/arrowdownred.gif"
Else
Console.WriteLine(ctrl2.ID)
End If
Next
End If
Next
Next
the code doesn't break or crash but I can't find the item and instead I can find find lblTitle in the second loop ctrl2.control("lblTitle")
Can I search for a control that is stored in the header template? If yes, How?