zachvaldez
asked on
How to refer to label control inside itemtemplate
I have the following mark up and code(I have problem in teh code side)
<asp:ListView ID="ListView1" DataSourceID="SqlDataSourc e1" Visible="false" DataKeyNames="UnitID" ConvertEmptyStringToNull=" true" runat="server" >
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblExcel" width="640px" cellspacing="0">
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr1" runat="server">
<%--<td>
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>--%>
<td>
<asp:Label ID="lblUnitID" runat="server" Text='<%#Eval("UnitID") %>' />
</td>
<td>
<asp:Label ID="ParishLabel" runat="server" Text='<%# Eval("School") %>' />
</td>
<td>
<asp:Button ID="SelectButton" runat="server" Text="Select"
CommandName="Select"
CommandArgument='<%#Eval(" School")%> ' />
</td>
<td>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</td>
</tr>
</ItemTemplate>
IN code behind I do to refer to it but getting Object not set...
Dim lblDone As Label = FindControl("Label2")
lblDone.Text = "Done"
I d like to see ways to access the label.
thnks
<asp:ListView ID="ListView1" DataSourceID="SqlDataSourc
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblExcel" width="640px" cellspacing="0">
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr1" runat="server">
<%--<td>
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>--%>
<td>
<asp:Label ID="lblUnitID" runat="server" Text='<%#Eval("UnitID") %>' />
</td>
<td>
<asp:Label ID="ParishLabel" runat="server" Text='<%# Eval("School") %>' />
</td>
<td>
<asp:Button ID="SelectButton" runat="server" Text="Select"
CommandName="Select"
CommandArgument='<%#Eval("
</td>
<td>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
</td>
</tr>
</ItemTemplate>
IN code behind I do to refer to it but getting Object not set...
Dim lblDone As Label = FindControl("Label2")
lblDone.Text = "Done"
I d like to see ways to access the label.
thnks
findcontrol as you used, looks under the main form, since your label is a child of the listview, you need to write ListView1.FindControl....
Actually that won't work either. The ListView can display a series of records, so you need to use FindControl on a specific item. For example, it you wanted to get the label in the first row of the ListView you would use:
Dim lblDone As Label = CType(ListView1.Items(0).FindControl("Label2"), Label)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Either way, code works but does not display the Label "DONE" in the row I assinged for <TD> </TD>
BTW, there are several rows, How would I reference which row or index Im clicking.
BTW, there are several rows, How would I reference which row or index Im clicking.
Have you got your ListView sat inside an AJAX updatepanel or anything like that?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.