473,387 Members | 1,283 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,387 software developers and data experts.

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="DlsBrochures" runat="server" RepeatDirection="Horizontal">
<ItemTemplate>
<img src='/images/<%# Eval("thumbnailName").ToString() %>' />
<br />

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

<div runat="server" id="DivDetailsLabel"> </div>

<a <%# GetViewDetailsAction() %>
href='/details.aspx?id=<%# Eval("brochureID").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 "DivDetailsLabel".

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

onMouseOver="javascript:document.getElementById('c tl00_CphMain_BlsMostRecent_dlsBrochures_ctl00_DivD etailsLabel').innerHTML = 'View details';"
onMouseOut="javascript:document.getElementById('ct l00_CphMain_BlsMostRecent_dlsBrochures_ctl00_DivDe tailsLabel').innerHTML = ' ';"

But the problem is I can only access the DataList "DlsBrochures" in the code
behind and not the "DivDetailsLabel" inside, and therefore I can't use
"DivDetailsLabel.ClientID" in my method "GetViewDetailsAction"...

How can I access other controls within the ItemTemplate of a DataList?
wb.
Jun 28 '06 #1
1 1940
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.ItemType == System.Web.UI.WebControls.ListItemType.Item ||
e.Item.ItemType == System.Web.UI.WebControls.ListItemType.Alternating Item)
{
object dataItem = e.Item.DataItem;

System.Web.UI.WebControls.Label lblDesc =
(System.Web.UI.WebControls.Label) e.Item.FindControl("LblDescription");
string lblDescName = lblDesc.ClientID;

// For "View Details" icon
System.Web.UI.WebControls.HyperLink lnkDetails =
(System.Web.UI.WebControls.HyperLink) e.Item.FindControl("LnkViewDetails");
lnkDetails.Attributes.Add("onmouseover",
"javascript:document.getElementById('" + lblDescName + "').innerHTML = 'view
details';");
lnkDetails.Attributes.Add("onmouseout",
"javascript:document.getElementById('" + lblDescName + "').innerHTML = ' ';");
}

And I should mention that I used <asp:Label> control (with
ID="LblDescription") instead of <div>, and <asp:Hyperlink> (with
ID="LnkViewDetails") 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="DlsBrochures" runat="server" RepeatDirection="Horizontal">
<ItemTemplate>
<img src='/images/<%# Eval("thumbnailName").ToString() %>' />
<br />

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

<div runat="server" id="DivDetailsLabel"> </div>

<a <%# GetViewDetailsAction() %>
href='/details.aspx?id=<%# Eval("brochureID").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 "DivDetailsLabel".

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

onMouseOver="javascript:document.getElementById('c tl00_CphMain_BlsMostRecent_dlsBrochures_ctl00_DivD etailsLabel').innerHTML = 'View details';"
onMouseOut="javascript:document.getElementById('ct l00_CphMain_BlsMostRecent_dlsBrochures_ctl00_DivDe tailsLabel').innerHTML = ' ';"

But the problem is I can only access the DataList "DlsBrochures" in the code
behind and not the "DivDetailsLabel" inside, and therefore I can't use
"DivDetailsLabel.ClientID" in my method "GetViewDetailsAction"...

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
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...
1
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...
4
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...
0
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...
1
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...
0
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...
0
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...
0
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...
3
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>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.