471,065 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,065 software developers and data experts.

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 1442
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.