views:

195

answers:

1

Hi all, I have filled the asp.net datagrid in codebehind file. while binding i have used the datagrid onItemDataBound event to add onmouseover and onmouseout event that looks lik this..

protected void dataGridSavedQueris_OnItemDataBound(Object sender, DataGridItemEventArgs e) {

    if (e.Item.ItemType == ListItemType.Item || 
        e.Item.ItemType == ListItemType.AlternatingItem)
    {
        e.Item.Attributes.Add("onmouseover", "dgRowHighlightOnWhenMouseOver(this,'" + e.Item.Cells[0].Text.ToString() + "');");
        e.Item.Attributes.Add("onmouseout", "dgRowHighlightOffWhenMouseOut (this,'" + e.Item.Cells[0].Text.ToString() + "');");
    }        
}

now, it renders properly. i mean the dgrowHighlightOnWhenMouseOver and dgRowHighlightOffWhenMouseOut is assigned every row of the datagrid expect the header and footer.

in onmouseover and onmouseout function, I show the div with values of associating id. what happening is whenever i move cursor one cell to another cell on the same row, it fires.

but, i need to fire the both events whenever I mouseover on the row not for cell..

how to do that?

thanks r.e

A: 

You might want to attach the mouseover/out on RowCreated rather than on ItemDataBound.

Something like this:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
    e.Row.Attributes.Add("onmouseover", "dgRowHighlightOnWhenMouseOver(this,'" + e.Row.Cells[0].Text.ToString() + "');");
    e.Row.Attributes.Add("onmouseout", "dgRowHighlightOffWhenMouseOut(this,'" + e.Row.Cells[0].Text.ToString() + "');");
  }
}

PS: I've not tried it out myself yet, so I'm not 100% sure :P

o.k.w
i have used only Asp.Net DataGrid not GridView. Eventhough I have tested with the GridView also.but , I get the same result...thanksr.e
eswaran
Ah, I missed out the DataGrid portion. Sorry mate.
o.k.w