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

Adding Tooltip text to a cell in a datagrid

what way do you code it? i tried the following but it wouldnt display it

lblAdd_info is a hidden field in the cell itself that contains the data i
want to display in the tooltip text. i added the following into the
ItemDatabound event for the grif but it wont display
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType =
ListItemType.Item Then

e.Item.Cells(5).ToolTip = "Craigs ToolTip Test!!"

End If

ideally i wanna set the tooltip text to a value returned from a dataset for
each row. but i cant even get it to display just a test string!

Cheers,
Craig
Nov 19 '05 #1
3 2527
Hi Craig,

Try it on the ItemCreated event? Here's some code, let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_ItemCreated _
(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.AlternatingItem Or _
e.Item.ItemType = ListItemType.Item Then
e.Item.Cells(0).ToolTip = "Tooltip for item: " &
e.Item.ItemIndex
e.Item.Cells(1).ToolTip = "Tooltip for item: " &
e.Item.ItemIndex
e.Item.Cells(2).ToolTip = "Tooltip for item: " &
e.Item.ItemIndex
End If
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 1
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource

"Craig G" <craig.gamble@y_arrasoftware.com> wrote in message
news:uz****************@tk2msftngp13.phx.gbl...
what way do you code it? i tried the following but it wouldnt display it

lblAdd_info is a hidden field in the cell itself that contains the data i
want to display in the tooltip text. i added the following into the
ItemDatabound event for the grif but it wont display
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType =
ListItemType.Item Then

e.Item.Cells(5).ToolTip = "Craigs ToolTip Test!!"

End If

ideally i wanna set the tooltip text to a value returned from a dataset
for
each row. but i cant even get it to display just a test string!

Cheers,
Craig


Nov 19 '05 #2
Oops. I wasn't paying enough attention. Here's what should work... get the
label from the hidden cell...

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_ItemDataBound _
(ByVal sender As Object, ByVal e As _
System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.AlternatingItem Or _
e.Item.ItemType = ListItemType.Item Then
e.Item.Cells(0).ToolTip = e.Item.Cells(3).Text
e.Item.Cells(1).ToolTip = "Test" & _
CType(e.Item.FindControl("secondstring"), Label).Text
End If
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("SecondString", GetType(String)))
Dim i As Integer
For i = 0 To 1
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = "Second string " + i.ToString()
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
<asp:datagrid id="DataGrid1" runat="server"
autogeneratecolumns="False">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:Label runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.IntegerValue") %>'>
</asp:label>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:Label runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Stringvalue") %>'>
</asp:label>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:Label runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.CurrencyValue") %>'>
</asp:label>
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:Label Visible="False" ID="secondstring"
runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SecondString")
%>'>
</asp:label>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
"Craig G" <craig.gamble@y_arrasoftware.com> wrote in message
news:uz****************@tk2msftngp13.phx.gbl...
what way do you code it? i tried the following but it wouldnt display it

lblAdd_info is a hidden field in the cell itself that contains the data i
want to display in the tooltip text. i added the following into the
ItemDatabound event for the grif but it wont display
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType =
ListItemType.Item Then

e.Item.Cells(5).ToolTip = "Craigs ToolTip Test!!"

End If

ideally i wanna set the tooltip text to a value returned from a dataset
for
each row. but i cant even get it to display just a test string!

Cheers,
Craig


Nov 19 '05 #3
that worked a treat Ken

Cheers!

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:eO*************@TK2MSFTNGP09.phx.gbl...
Hi Craig,

Try it on the ItemCreated event? Here's some code, let us know if it helps?
Ken
Microsoft MVP [ASP.NET]
Toronto

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_ItemCreated _
(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.AlternatingItem Or _
e.Item.ItemType = ListItemType.Item Then
e.Item.Cells(0).ToolTip = "Tooltip for item: " &
e.Item.ItemIndex
e.Item.Cells(1).ToolTip = "Tooltip for item: " &
e.Item.ItemIndex
e.Item.Cells(2).ToolTip = "Tooltip for item: " &
e.Item.ItemIndex
End If
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 1
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource

"Craig G" <craig.gamble@y_arrasoftware.com> wrote in message
news:uz****************@tk2msftngp13.phx.gbl...
what way do you code it? i tried the following but it wouldnt display it

lblAdd_info is a hidden field in the cell itself that contains the data i want to display in the tooltip text. i added the following into the
ItemDatabound event for the grif but it wont display
If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType =
ListItemType.Item Then

e.Item.Cells(5).ToolTip = "Craigs ToolTip Test!!"

End If

ideally i wanna set the tooltip text to a value returned from a dataset
for
each row. but i cant even get it to display just a test string!

Cheers,
Craig

Nov 19 '05 #4

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

Similar topics

5
by: Sue | last post by:
On code-behind page: (attributes set programatically for each of these elements) linkbutton added to tablecell textbox added to tablecell tablecells added to tablerow tablerow added to table...
2
by: Stephen | last post by:
I'm trying to work with a datagrid column in order to display a tooltip in a datagrid cell. The reason I am doing this is because I have some long strings being returned and I don't want the rows...
2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
0
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. ...
1
by: Lars Netzel | last post by:
I need to have a Tooltip on each Cell in a datagrid, I don't know how to do this. I'm using Styles to the datagrid (Which I asume most people do since you never need to show all the fields from the...
2
by: Tomek R. | last post by:
Hello ! I've got weird problem when adding new datagrid item. Here is the situation: my grid dgDeps is binded to DepartmentList arraylist, stored in Session between round-trips.. To add new...
5
by: Lars Netzel | last post by:
I need to have a Tooltip on each Cell in a datagrid, I don't know how to do this. I'm using Styles to the datagrid (Which I asume most people do since you never need to show all the fields from the...
2
by: james | last post by:
I have been looking for a way to reproduce the tooltip that Access displays when scrolling the Datagrid that shows the record count (changes as you move the thumb up or down). So far, nothing I...
2
by: geronimi | last post by:
I want a tooltip (in an item in a datagrid) to stay for more then 5 seconds (standard) visible, Do I have to write my own Toolip or can I change a setting somewhere to increase the tooltip visible...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.