GridView问题?鼠标点到GridView的某一行,如何知道点到的是第几行?
解决速结贴.
谢谢诶.

解决方案 »

  1.   

    aspx 页用<%#Container.DataItemIndex %>
    cs页用 
    .SelectedIndex
      

  2.   


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onmouseover"] = "this.style.color='Red';";
                e.Row.Attributes["onmouseout"] = "this.style.color='Black';";
                e.Row.Attributes["onclick"] = string.Format("alert('{0}')", e.Row.RowIndex);
            }
        }
      

  3.   


    protected void GV_Item_SelectedIndexChanged(object sender, EventArgs e)
        {
            int value = GV_Item.SelectedIndex;
        }
      

  4.   


    支持。
    值得注意的是:e.Row.RowIndex是从0开始,实际行号要加1。
    不过我一般在用GridView显示数据的时候都会将第一行显示序号,也就是行号了。在上面的函数中添加如下代码:
    if (e.Row.RowIndex > -1)
            {
                int id = e.Row.RowIndex + 1;
                e.Row.Cells[0].Text = id.ToString();
            }