468,115 Members | 2,024 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,115 developers. It's quick & easy.

trouble with FindControl

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?
Oct 29 '08 #1
2 1393
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************@hotmail.com.NOSPAMa écrit dans le message de groupe
de discussion : OD**************@TK2MSFTNGP05.phx.gbl...
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?
Oct 29 '08 #2
"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:OD**************@TK2MSFTNGP05.phx.gbl...
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

Oct 29 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by James G. Beldock | last post: by
reply views Thread by 2obvious | last post: by
1 post views Thread by Krish | last post: by
14 posts views Thread by aroraamit81 | last post: by
7 posts views Thread by AAaron123 | last post: by
4 posts views Thread by Hillbilly | last post: by
5 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.