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