473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How do I find a control in a datalist?

I have this code:

protected void DataList1_ItemCreated(object sender,
DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Label lbl = (Label)DataList1.FindControl("lblTest");
Response.Write(lbl.Text);
}
}

First, do I have to have that ListItemType.item, etc. stuff in asp.net
2.0? On the findcontrol, I did some searching and saw where I had to
have a something like

DataList1.FindControl(myID).FindControl("myControl ");

I don't know what the myID is or if I need it.

Thank you for any help.

Oct 11 '06 #1
1 1510
Ya, you need to check for the Item || ItemType, since ItemCreated fires for
the headeritem and footeritem and the other templates, and you won't find
your control in there.

simply do:

e.Item.FindControl("lblTest");
e is the 2nd argument, e.Item is the DataListItem (which you can *think* of
as the actual row being bound)...within this row is the control you want to
find.

you CAN do it like DataList1.FindControl("XXX").FindControl("myContro l");

but DataList1.FindControl("XXXX") just returns the same control as e.Item.

Karl
--
http://www.openmymind.net/
http://www.codebetter.com/
<ne***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>I have this code:

protected void DataList1_ItemCreated(object sender,
DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Label lbl = (Label)DataList1.FindControl("lblTest");
Response.Write(lbl.Text);
}
}

First, do I have to have that ListItemType.item, etc. stuff in asp.net
2.0? On the findcontrol, I did some searching and saw where I had to
have a something like

DataList1.FindControl(myID).FindControl("myControl ");

I don't know what the myID is or if I need it.

Thank you for any help.

Oct 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
2
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the...
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
2
by: Greg Fischer | last post by:
I need to access the properties of a control that is nested in 2 datalists. How do you use findcontrol method to do that? what I have is like this: <asp:datalist id="dlist" runat="server">...
1
by: caldera | last post by:
Hi, I want to find the web user control in the datalist. I iterate the datalist using foreach statement in the DataListItem and in thi DataListItem I iterate all Controls objects but I can't find...
4
by: Sam Martin | last post by:
Hi, I have got a User Control that contains for the sake of argument, a single DataList control. eg. <asp:DataList id="DataListMain" runat="server" RepeatDirection="Horizontal"...
1
by: shantanu_kush | last post by:
Hi there, I am using a DataList in a composite control. The DataList has an Custom ItemTemplate(ITemplate) which adds a Button to the DataList Item as shown in the code below : public class...
6
by: Victor | last post by:
Hi. all I have a customize web control. I have three simple properties and customized render class. then I add this control into my datalist like <asp:DataList ID="datalist" runat="server"...
1
by: Salim | last post by:
Hi, I'm trying to get UniqueID of a linkbutton. I have 2 web user controls. And a master page. In fisrst web user control there is a datalist. In datalist ItemCreated event, I try to find...
1
by: Sripelly | last post by:
I am using a Datalist control which contains 4 lables,2 textboxes,..etc. How to find the label in the Datalist control
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.