473,652 Members | 3,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referencing Controls in DataList

WB
Hi,

I would like to do something like this page:
http://www.stocklayouts.com/Products...y.aspx?kwid=38
Notice when you mouse-over any of the icons under each thumbnail, a little
description will appear to tell you what the icon is for.

Okay, so I have a DataList in a stucture like this:

<asp:DataList ID="DlsBrochure s" runat="server" RepeatDirection ="Horizontal ">
<ItemTemplate >
<img src='/images/<%# Eval("thumbnail Name").ToString () %>' />
<br />

<%# Eval("brochureN ame").ToString( ) %><br />

<div runat="server" id="DivDetailsL abel"> </div>

<a <%# GetViewDetailsA ction() %>
href='/details.aspx?id =<%# Eval("brochureI D").ToString () %>'>

<img src="/images/icons/viewDetails.gif " alt="view details" />

</a>
</ItemTemplate>
</asp:DataList>

The HTML <img> tag shows the thumbnail of a brochure, with the name of the
brochure displayed underneath. There is a icon which links user to the
details page when clicked, and when mouse-over, it displays "View Details" in
the <div> tag with ID "DivDetailsLabe l".

Now the <a> tag calls the method "GetViewDetails Action" which exists in the
code-behind, and is supposed to churn out the javascript:

onMouseOver="ja vascript:docume nt.getElementBy Id('ctl00_CphMa in_BlsMostRecen t_dlsBrochures_ ctl00_DivDetail sLabel').innerH TML = 'View details';"
onMouseOut="jav ascript:documen t.getElementByI d('ctl00_CphMai n_BlsMostRecent _dlsBrochures_c tl00_DivDetails Label').innerHT ML = ' ';"

But the problem is I can only access the DataList "DlsBrochur es" in the code
behind and not the "DivDetailsLabe l" inside, and therefore I can't use
"DivDetailsLabe l.ClientID" in my method "GetViewDetails Action"...

How can I access other controls within the ItemTemplate of a DataList?
wb.
Jun 28 '06 #1
1 1969
WB
Hi,

I've figured out a way to do it. Here it is, just to share with everyone:

I hook up a method to the ItemDataBound event of the DataList. This method
goes something like this:

if (e.Item.ItemTyp e == System.Web.UI.W ebControls.List ItemType.Item ||
e.Item.ItemType == System.Web.UI.W ebControls.List ItemType.Altern atingItem)
{
object dataItem = e.Item.DataItem ;

System.Web.UI.W ebControls.Labe l lblDesc =
(System.Web.UI. WebControls.Lab el) e.Item.FindCont rol("LblDescrip tion");
string lblDescName = lblDesc.ClientI D;

// For "View Details" icon
System.Web.UI.W ebControls.Hype rLink lnkDetails =
(System.Web.UI. WebControls.Hyp erLink) e.Item.FindCont rol("LnkViewDet ails");
lnkDetails.Attr ibutes.Add("onm ouseover",
"javascript:doc ument.getElemen tById('" + lblDescName + "').innerHT ML = 'view
details';");
lnkDetails.Attr ibutes.Add("onm ouseout",
"javascript:doc ument.getElemen tById('" + lblDescName + "').innerHT ML = ' ';");
}

And I should mention that I used <asp:Label> control (with
ID="LblDescript ion") instead of <div>, and <asp:Hyperlin k> (with
ID="LnkViewDeta ils") instead of <a>...
wb.


"WB" wrote:
Hi,

I would like to do something like this page:
http://www.stocklayouts.com/Products...y.aspx?kwid=38
Notice when you mouse-over any of the icons under each thumbnail, a little
description will appear to tell you what the icon is for.

Okay, so I have a DataList in a stucture like this:

<asp:DataList ID="DlsBrochure s" runat="server" RepeatDirection ="Horizontal ">
<ItemTemplate >
<img src='/images/<%# Eval("thumbnail Name").ToString () %>' />
<br />

<%# Eval("brochureN ame").ToString( ) %><br />

<div runat="server" id="DivDetailsL abel"> </div>

<a <%# GetViewDetailsA ction() %>
href='/details.aspx?id =<%# Eval("brochureI D").ToString () %>'>

<img src="/images/icons/viewDetails.gif " alt="view details" />

</a>
</ItemTemplate>
</asp:DataList>

The HTML <img> tag shows the thumbnail of a brochure, with the name of the
brochure displayed underneath. There is a icon which links user to the
details page when clicked, and when mouse-over, it displays "View Details" in
the <div> tag with ID "DivDetailsLabe l".

Now the <a> tag calls the method "GetViewDetails Action" which exists in the
code-behind, and is supposed to churn out the javascript:

onMouseOver="ja vascript:docume nt.getElementBy Id('ctl00_CphMa in_BlsMostRecen t_dlsBrochures_ ctl00_DivDetail sLabel').innerH TML = 'View details';"
onMouseOut="jav ascript:documen t.getElementByI d('ctl00_CphMai n_BlsMostRecent _dlsBrochures_c tl00_DivDetails Label').innerHT ML = ' ';"

But the problem is I can only access the DataList "DlsBrochur es" in the code
behind and not the "DivDetailsLabe l" inside, and therefore I can't use
"DivDetailsLabe l.ClientID" in my method "GetViewDetails Action"...

How can I access other controls within the ItemTemplate of a DataList?
wb.

Jun 29 '06 #2

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

Similar topics

1
2667
by: Scott Schluer | last post by:
Hello, I've got myself a small problem and I'm hoping someone can help. I have a DataList called dlProducts (displays products from a database). Within the <ItemTemplate> container of the DataList, I have a PlaceHolder control called phVariations. During the ItemDataBound event for dlProducts, I dynamically create a few DropDownLists (again, from a database) and .Add the DropDownList to the PlaceHolder control. That all works just...
1
3620
by: bill yeager | last post by:
I have a radiobuttonlist inside a datalist. I also have a datagrid inside the datalist. The data and the controls are rendering just fine. However, I need to find these controls inside the datalist in order to programatically perform some logic. I have the following in my HTML which is inside the ItemTemplate of the datalist:
4
3081
by: V. Jenks | last post by:
What seems like a simple thing is apparently not so straightforward? I have a datalist. Inside of that datalist is an <itemtemplate> secion which contains other server controls such as a label, a radiobuttonlist, etc. I'm driving myself insane trying to figure out how to get
0
1057
by: Luis Esteban Valencia | last post by:
Hi, I'm in serious need of help. I have a datalist that will list a number of 'Agents'. When the user selects the edit button of my datalist, I put it into edit mode. When putting the datalist into edit mode I need to load the controls that I have placed inside the 'EditItemTemplate' section of the datalist. I cannot, however do this as I can't seem to find the controls. I have tried using datalist.findcontrol(datalist.edititemindex) and...
1
1089
by: David | last post by:
Hello. I have one question about DataList control: I have one DaaList control on my page in which I put some controls, for example I put two labels in header section and five labels in items section. But now I can't access this labels from code by their names:( So how can I access controls in DataList control form code? Thank you.
0
1694
by: bryanp10 | last post by:
I have a DataList on my page which contains multiple DropDownLists. My page defaults to showing six rows in the DataList. I want the ability to dynamically add rows if needed. Right now I'm just using an empty table with X rows, and adding a new row to the table that the DataList is bound to. However, I can't figure out a way to do this and at the same time maintain the current viewstate of the existing controls. When I call...
0
1158
by: ElGordo | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the OnEditCommand event is raised, I try to do the following: 1. Find the selected datalist item in which the nested datagrid raised the event. (by calling getDataGridReference and returning the DataList's selectedIndex)
0
1695
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the OnEditCommand event is raised, I try to do the following: 1. Find the selected datalist item in which the nested datagrid raised the event. (by calling getDataGridReference and returning the DataList's selectedIndex)
3
1690
by: Jon Paal | last post by:
how do I load controls to the templates for the DataList control. <asp:datalist id="dl1" runat="server" > <ItemTemplate> " how to load control(s) here ????" </ItemTemplate> </asp:datalist>
0
8367
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.