473,387 Members | 2,436 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.

DataList Row ToolTip

A DataList displays 3 columns - Product, Category & Price. These
columns are populated with records from a SQL Server 2005 DB table.
Apart from the above 3 DB columns that the resultset retrieves, there
is another DB column named 'Description'. Though the resultset fetches
this column as well along with the above 3 columns, I am excluding the
Description column from the DataList - the reason being most of the
descriptions are pretty long & this may drastically increase the width
of the entire DataList which I would like to avoid. I don't prefer
wrapping any column text in the DataList as well.

This is why I want that when a user hovers his mouse over one
particular row in the DataList, that row should display a ToolTip for
the DB record it houses & the ToolTip should show the description of
that particular record.

For e.g. if one of the DB records under the DB columns 'Product',
'Category', 'Price', 'Description' is 'Lancer', 'Car', '25000', 'This
car is blah...blah...blah...blah...blah....' respectively, then one of
the rows in the DataList would be

Lancer Car 25000

Now when a user hovers his mouse over this row in the DataList, a
ToolTip stating 'This car is blah...blah...blah...blah...blah....'
should come up.

In other words, hovering the mouse over different rows in the DataList
should show different ToolTips (which should be the corresponding
description). How do I do this?

Nov 20 '06 #1
4 7787
I am not sure on hovering over a row I have tried this with the ToolTip
on the datalist item but it didn't work. If you add a control you can
do it like this... Add a label to the datalist row and have it contain
the text you want in the tooltip, then set visible=false on that label.
then do this...

//Loop through the datalist
foreach (DataListItem dl in DataList1.Items)
{
//FIND THE CONTROL YOU WANT TO HOVER OVER
Label lbl = (Label)dl.FindControl("user_firstnameLabel");

//FIND THE INVISIBLE CONTROL WITH THE TOOLTIP INFO
Label lblEmail = (Label)dl.FindControl("user_emailLabel");

//SET THE TOOLTIP TO THE TOOLTIP INFO
lbl.ToolTip = lblEmail.Text;
}

This is a simple DL that shows a label with a first name and then when
it is hovered over it shows the email address of the individual.

Hope this helps!

-Jason

Nov 20 '06 #2
"jb******@gmail.com" wrote:
I am not sure on hovering over a row I have tried this with the ToolTip
on the datalist item but it didn't work.
You could use the title attribute of the table row, e.g.
<tr title="Long description of record">
<td>Product Name</td>
<td>Product Category</td>
<td>Price</td>
</tr>
Nov 20 '06 #3
Jason, I found a far simpler way to display the ToolTip when the mouse
hovers over any row in a DataList. Earlier, I was populating the
<ItemTemplate/in the DataList using Literal controls in this way:

<asp:DataList ID="dlCart" runat="server">
<HeaderTemplate>
<table border="2" width="100%">
<tr>
<th>PRODUCT</th>
<th>CATEGORY</th>
<th>PRICE</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Container.DataItem("Product") %></td>
<td><%# Container.DataItem("Category") %></td>
<td><%# Container.DataItem("Price") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>

To make the ToolTips appear, I replaced the Literal controls with Label
controls within the <ItemTemplate/>

<ItemTemplate>
<tr>
<td>
<asp:Label ID="lbl1" Text='<%# Container.DataItem("Product") %>'
ToolTip='<%# Container.DataItem("Description") %>' Width="100%"
runat="server"/>
</td>
<td>
<asp:Label ID="lbl2" Text='<%# Container.DataItem("Category") %>'
ToolTip='<%# Container.DataItem("Description") %>' Width="100%"
runat="server"/>
</td>
<td>
<asp:Label ID="lbl3" Text='<%# Container.DataItem("Price") %>'
ToolTip='<%# Container.DataItem("Description") %>' Width="100%"
runat="server"/>
</td>
</tr>
</ItemTemplate>

Often it happens that the width of a <tdturns out to be larger than
the length of the text (in this case, width of the Label) due to which
only a part of the <tdhouses the text & the remaining part of the
<tdremains empty (without any text). Setting the "Width" property of
the Labels to 100% ensures that the ToolTips would appear irrespective
of where the mouse hovers over a particular <td>. Avoiding it will make
the ToolTip appear only when the mouse hovers over the Label control
(or the text) in a particular <tdbut not when the mouse hovers over
any empty space within a <td>.

In short, let the mouse hover over any region in a row - the ToolTip
will always appear.

That's it!

The suggestion you had given to display the ToolTips - I doubt whether
it will work because when I tried it out (using Label controls), the
ToolTips appeared only when the Labels' Visible property was set to
True. The ToolTips didn't appear when the Labels' Visible property was
set to False. Have you tried it out?
jb******@gmail.com wrote:
I am not sure on hovering over a row I have tried this with the ToolTip
on the datalist item but it didn't work. If you add a control you can
do it like this... Add a label to the datalist row and have it contain
the text you want in the tooltip, then set visible=false on that label.
then do this...

//Loop through the datalist
foreach (DataListItem dl in DataList1.Items)
{
//FIND THE CONTROL YOU WANT TO HOVER OVER
Label lbl = (Label)dl.FindControl("user_firstnameLabel");

//FIND THE INVISIBLE CONTROL WITH THE TOOLTIP INFO
Label lblEmail = (Label)dl.FindControl("user_emailLabel");

//SET THE TOOLTIP TO THE TOOLTIP INFO
lbl.ToolTip = lblEmail.Text;
}

This is a simple DL that shows a label with a first name and then when
it is hovered over it shows the email address of the individual.

Hope this helps!

-Jason
Nov 20 '06 #4
Yes, it worked. The Visible = false would be on the label with the
tooltip text not the one you would hover over..

Your solutions looks better anyway.

Thanks!

Jason
rn**@rediffmail.com wrote:
Jason, I found a far simpler way to display the ToolTip when the mouse
hovers over any row in a DataList. Earlier, I was populating the
<ItemTemplate/in the DataList using Literal controls in this way:

<asp:DataList ID="dlCart" runat="server">
<HeaderTemplate>
<table border="2" width="100%">
<tr>
<th>PRODUCT</th>
<th>CATEGORY</th>
<th>PRICE</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Container.DataItem("Product") %></td>
<td><%# Container.DataItem("Category") %></td>
<td><%# Container.DataItem("Price") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>

To make the ToolTips appear, I replaced the Literal controls with Label
controls within the <ItemTemplate/>

<ItemTemplate>
<tr>
<td>
<asp:Label ID="lbl1" Text='<%# Container.DataItem("Product") %>'
ToolTip='<%# Container.DataItem("Description") %>' Width="100%"
runat="server"/>
</td>
<td>
<asp:Label ID="lbl2" Text='<%# Container.DataItem("Category") %>'
ToolTip='<%# Container.DataItem("Description") %>' Width="100%"
runat="server"/>
</td>
<td>
<asp:Label ID="lbl3" Text='<%# Container.DataItem("Price") %>'
ToolTip='<%# Container.DataItem("Description") %>' Width="100%"
runat="server"/>
</td>
</tr>
</ItemTemplate>

Often it happens that the width of a <tdturns out to be larger than
the length of the text (in this case, width of the Label) due to which
only a part of the <tdhouses the text & the remaining part of the
<tdremains empty (without any text). Setting the "Width" property of
the Labels to 100% ensures that the ToolTips would appear irrespective
of where the mouse hovers over a particular <td>. Avoiding it will make
the ToolTip appear only when the mouse hovers over the Label control
(or the text) in a particular <tdbut not when the mouse hovers over
any empty space within a <td>.

In short, let the mouse hover over any region in a row - the ToolTip
will always appear.

That's it!

The suggestion you had given to display the ToolTips - I doubt whether
it will work because when I tried it out (using Label controls), the
ToolTips appeared only when the Labels' Visible property was set to
True. The ToolTips didn't appear when the Labels' Visible property was
set to False. Have you tried it out?
jb******@gmail.com wrote:
I am not sure on hovering over a row I have tried this with the ToolTip
on the datalist item but it didn't work. If you add a control you can
do it like this... Add a label to the datalist row and have it contain
the text you want in the tooltip, then set visible=false on that label.
then do this...

//Loop through the datalist
foreach (DataListItem dl in DataList1.Items)
{
//FIND THE CONTROL YOU WANT TO HOVER OVER
Label lbl = (Label)dl.FindControl("user_firstnameLabel");

//FIND THE INVISIBLE CONTROL WITH THE TOOLTIP INFO
Label lblEmail = (Label)dl.FindControl("user_emailLabel");

//SET THE TOOLTIP TO THE TOOLTIP INFO
lbl.ToolTip = lblEmail.Text;
}

This is a simple DL that shows a label with a first name and then when
it is hovered over it shows the email address of the individual.

Hope this helps!

-Jason
Nov 20 '06 #5

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

Similar topics

0
by: Yves Royer | last post by:
Hi, I'm currently writing an application (in VS 2005 bèta 2) and made some own user controls. In each user control I added a ToolTip object so i can set some tooltips on checkboxes etc. What...
0
by: Yves Royer | last post by:
Hi, My first post didn't show up so here's a second try. I'm currently writing an application (in VS 2005 bèta 2) and made some own user controls. In each user control I added a ToolTip object...
0
by: Arjen | last post by:
Hello, Here is my datalist. <asp:DataList id="myDataList" CellPadding="4" Width="100%" runat="server"> <ItemTemplate> <span class="Normal"> <asp:HyperLink id="link" Text='<%#...
0
by: Richard Steele | last post by:
I have a default page that I load usercontrols depending on requirements through a master template using a PlaceHolder i.e. //some logic here..... Control UCUsers =...
7
by: Aussie Rules | last post by:
Hi, I have a data list that is bound to a datasource which is just a list of products from a sql table. What I want to do is configure the data list so that when i person clicks on an item in...
2
by: sck10 | last post by:
Hello, I am converting a DataList from vb to c#. I am having a problem converting the Replace function to c#. Any help with this would be appreciated. <asp:DataList id="dlstPhotoGallery"...
0
by: Sudheer Aalla | last post by:
Hi, When I try to reference the radiobuttonlist control in edititemtemplate in ItemDataBound event of datalist control I am getting NULL reference. I am trying to pre select the yes/no button...
5
by: =?Utf-8?B?cGV0ZTE5Njk=?= | last post by:
I use Visual Studio 2005 and created a very simple Form with one button. I added a Tooltip for that button. It shows fine the first time I hover over that button. But if I let it disappear by the...
16
by: Charles Law | last post by:
I have to take this personally now. Tooltips have been flakey since the dawn of .NET, but to still have to put up with a disappearing tooltip in VS 2008 is getting beyond a joke. Tooltips have...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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
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.