GridView的技巧 绑定行事件,取得单元格值,或取得单元格控件方法,鼠标经过样式

 

  //取得GV单元格值的三种方法
          1/  Control ID = _gridView.Rows[i].Cells[0].Controls[1];// 可以取得属性为 Visible="False" 的控件
              string ID_str = ((Label)ID).Text;
            if (e.Row.RowType == DataControlRowType.DataRow)//判断行有没有数据
           {
                   DataRowView myrows = (DataRowView)e.Row.DataItem;//把数据放到View里,使用下标就可以取出来
           }
          2/  string a= e.Row.Cells[9].Text
         
          3/  LinkButton link = (LinkButton)e.Row.FindControl("LinkButton1");
              string ID_str = ((Label)link ).Text;

         string on_link = ClientScript.GetPostBackClientHyperlink(link, "");//点击事件link 为要绑定的控件
         e.Row.Attributes["onclick"] = on_link;绑定
        
         e.Row.Attributes.Add("onMouseOver", "t=this.style.backgroundColor;this.style.backgroundColor='#ebebce'");
         e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=t");
         e.Row.Attributes.CssStyle.Add("cursor", "hand");

你可能感兴趣的:(String)