Connecting Tech Pros Worldwide Forums | Help | Site Map

trouble with FindControl

Jeff
Guest
 
Posts: n/a
#1: Oct 29 '08
hi

asp.net 2.0

I'm having trouble with findcontrol. The problem is in the code below. The
is that this line don't work:
label = (Label)e.Item.FindControl("lblKode");
label has a NULL value after that line is executed. I've checked and double
checked the spelling of the control name, it is named lblKode.

label = (Label)e.Item.FindControl("lblDesc"); works fine. that line I just
copied from the line above and changed lblKode to lblDesc, this line works
without any problem.. strange

protected void rptPhoneType_ItemDataBound(Object Sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
PhoneTypeDetail phonetype = (PhoneTypeDetail)e.Item.DataItem;
Label label;
label = (Label)e.Item.FindControl("lblKode");
label.Text = phonetype.Type.ToString();
label = (Label)e.Item.FindControl("lblDesc");
label.Text = phonetype.Desc;
}
}

here is markup of the Repeater
<asp:Repeater ID="rptPhoneType" runat="server"
OnItemDataBound="rptPhoneType_ItemDataBound">
<ItemTemplate>
<asp:Label ID="lblKode" runat="server"></asp:Label>
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server"></asp:Label>
</ItemTemplate>
</asp:Repeater>

any suggestions?



Patrice
Guest
 
Posts: n/a
#2: Oct 29 '08

re: trouble with FindControl


Is this normal you have two ItemTemplate in your repeater ?

Else my approach would be to just dump the content. For now I would say the
second template overrides the first template...

--
Patrice

"Jeff" <it_consultant1@hotmail.com.NOSPAMa écrit dans le message de groupe
de discussion : OD2NWtbOJHA.4876@TK2MSFTNGP05.phx.gbl...
Quote:
hi
>
asp.net 2.0
>
I'm having trouble with findcontrol. The problem is in the code below. The
is that this line don't work:
label = (Label)e.Item.FindControl("lblKode");
label has a NULL value after that line is executed. I've checked and
double checked the spelling of the control name, it is named lblKode.
>
label = (Label)e.Item.FindControl("lblDesc"); works fine. that line I just
copied from the line above and changed lblKode to lblDesc, this line works
without any problem.. strange
>
protected void rptPhoneType_ItemDataBound(Object Sender,
RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
PhoneTypeDetail phonetype = (PhoneTypeDetail)e.Item.DataItem;
Label label;
label = (Label)e.Item.FindControl("lblKode");
label.Text = phonetype.Type.ToString();
label = (Label)e.Item.FindControl("lblDesc");
label.Text = phonetype.Desc;
}
}
>
here is markup of the Repeater
<asp:Repeater ID="rptPhoneType" runat="server"
OnItemDataBound="rptPhoneType_ItemDataBound">
<ItemTemplate>
<asp:Label ID="lblKode" runat="server"></asp:Label>
</ItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server"></asp:Label>
</ItemTemplate>
</asp:Repeater>
>
any suggestions?
>
Mark Rae [MVP]
Guest
 
Posts: n/a
#3: Oct 29 '08

re: trouble with FindControl


"Jeff" <it_consultant1@hotmail.com.NOSPAMwrote in message
news:OD2NWtbOJHA.4876@TK2MSFTNGP05.phx.gbl...
Quote:
Any suggestions?
Patrice is correct. You can't have more than one <ItemTemplate /in an
<asp:Repeater />

Well, you can, but all except the final one will be ignored...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Closed Thread