日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

.net dataGridView当鼠标经过时当前行背景色变色;然后【给GridView增加单击行事件,并获取单击行的数据填充到页面中的控件中】...

發(fā)布時間:2025/7/14 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .net dataGridView当鼠标经过时当前行背景色变色;然后【给GridView增加单击行事件,并获取单击行的数据填充到页面中的控件中】... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.首先在前臺dataGridview屬性中增加onRowDataBound屬性事件

2.然后在后臺Observing_RowDataBound事件中增加代碼

protected void Observing_RowDataBound(object sender, GridViewRowEventArgs e)
{

  //首先判斷是否是數(shù)據(jù)行
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
    //當(dāng)鼠標(biāo)停留時更改背景色
    e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#eed6d6'");
    //當(dāng)鼠標(biāo)移開時還原背景色
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  }

}

此隨筆參考原文?http://www.cnblogs.com/Ryan_j/archive/2010/10/04/1842038.html GridView72般絕技

3.下面是自己增加的內(nèi)容【給GridView增加單擊行事件,并獲取單擊行的數(shù)據(jù)填充到頁面中的控件中】

e.Row.Attributes.Add("onclick", "getGridViewValue('" + strName + "','" + strSex + "','" + strAge + "','" + Server.UrlEncode(strDiag).Replace("+", "%20") + "')");

strDiag診斷這個字段有可能會出現(xiàn)有空格的現(xiàn)象,如果有空格,不編碼傳到前臺js會報(bào)錯,所以這里要編碼。而vs編碼后空格就會變成+號,所以這里要用Server.UrlEncode編碼后并將+號替換為%20,前臺js中接收并解碼就成功了,單擊GridView填充數(shù)據(jù)到Textbox控件中。

【最后附上代碼】

【后臺】

1 protected void Observing_RowDataBound(object sender, GridViewRowEventArgs e) 2 { 3 4 //首先判斷是否是數(shù)據(jù)行 5 if (e.Row.RowType == DataControlRowType.DataRow) 6 { 7 //當(dāng)鼠標(biāo)停留時更改背景色 8 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#eed6d6'"); 9 //當(dāng)鼠標(biāo)移開時還原背景色 10 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"); 11 int index = e.Row.DataItemIndex; 12 DataTable dt = (DataTable)ObservingGrid.DataSource; 13 string strName = dt.Rows[index][2].ToString(); 14 string strSex = dt.Rows[index][3].ToString(); 15 string strAge = dt.Rows[index][4].ToString(); 16 string strDiag = dt.Rows[index][5].ToString(); 17 //DY.Web.UI.Dialog.LhgDialog.Alert(this, "getGridViewValue('" + strName + "','" + strSex + "','" + strAge + "','" + Uri.EscapeDataString(strDiag) + "')", ""); 18 e.Row.Attributes.Add("onclick", "getGridViewValue('" + strName + "','" + strSex + "','" + strAge + "','" + Server.UrlEncode(strDiag).Replace("+", "%20") + "')"); 19 20 } 21 22 }

【js】

1 <script type="text/javascript"> 2 function getGridViewValue(name, sex, age, diag) { 3 document.getElementById("TbName").value = name; 4 document.getElementById("DdlbSex").value = sex; 5 document.getElementById("TbAge").value = age; 6 document.getElementById("TbDiagnosis").value = decodeURI(diag); 7 } 8 </script>

?

轉(zhuǎn)載于:https://www.cnblogs.com/MingAndWoNiu/p/4733790.html

總結(jié)

以上是生活随笔為你收集整理的.net dataGridView当鼠标经过时当前行背景色变色;然后【给GridView增加单击行事件,并获取单击行的数据填充到页面中的控件中】...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。