开发者

problem in datagrid mouseover and mouseout events.. in asp.net

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 dgRowHighlightOffWhen开发者_开发问答MouseOut 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜