By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

Adding Tooltip text to a cell in a datagrid

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.