Tags: ado, cbelow, cell, colors, cursor, databind, datagrid, eventbut, example, grid, hand, mouseover, net, particular, specify

How to specify a hand cursor for a datagrid cell on the databind?

On .Net » .Net ADO

1,465 words with 3 Comments; publish: Mon, 31 Dec 2007 16:39:00 GMT; (10062.50, « »)

How do you specify a hand cursor for a particular cell in a data grid in C#?

Below is an example where I change cell colors for a mouseover event

but I'm not sure how to also set the cursor to a hand. The syntax I'm using below is not correct. I think it might be right for VB rather than C#.

public void formatItemsOnDatabind (Object sender, DataGridItemEventArgs e)


if ( e.Item.ItemType == ListItemType.Item | e.Item.ItemType == ListItemType.AlternatingItem )


e.Item.Cells[0].Style("cursor") = "hand";

e.Item.Cells[0].Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'");

e.Item.Cells[0].Attributes.Add("onmouseout", "this.style.backgroundColor='White'");



All Comments

Leave a comment...

    • you can set the style of the column. For example:

      <asp:BoundColumn style="cursor:hand;">

      #1; Mon, 31 Dec 2007 16:40:00 GMT
    • What is the syntax for the same thing, only applied programatically to datagrid items as they are being bound?

      For instance, to set an onmouseover event for a table cell I can specify:

      e.Item.Cells[0].Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'");

      I would expect something similar for setting the cursor like below, only this doesn't work.

      e.Item.Cells[0].Attributes.Add("cursor", "hand");

      Thanks in advance for any help.

      #2; Mon, 31 Dec 2007 16:41:00 GMT
    • All you need to do is to assign a CSS Class to the column. For example,

      col.cssClass = "myStyle"

      #3; Mon, 31 Dec 2007 16:42:00 GMT