国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

js實現GridView單選效果自動設置交替行、選中行、鼠標移動行背景

2024-05-06 14:09:49
字體:
來源:轉載
供稿:網友
后臺代碼
代碼如下:
/// <summary>
/// 數據行綁定事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvProduct_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
GridViewRow row = e.Row;
CheckBox ckb = row.Cells[0].FindControl("ckb") as CheckBox;
Label ProductID = row.Cells[0].FindControl("lblProductID") as Label;
//當鼠標停留時更改背景色
row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00A9FF'");
//當鼠標移開時還原背景色
row.Attributes.Add("onmouseout", "gvProducts_onmouseout('" + gvProducts.ClientID + "','" + ckb.ClientID + "',this) ");
//當鼠標移開時還原背景色
row.Attributes.Add("onclick", "SelectRadio('" + gvProducts.ClientID + "','" + ckb.ClientID + "','" + ProductID.Text + "',this) ");
ckb.Attributes.Add("onclick", "SelectRadio('" + gvProducts.ClientID + "','" + ckb.ClientID + "','" + ProductID.Text + "',document.getElementById('" + row.ClientID + "')) ");
}
catch (Exception ex)
{
}
}

前臺代碼
代碼如下:
/****************************************************/
//功能:鼠標移出時設置行顏色
//說明:onmouseout事件時使用
//作者:XXXXX
//日期:2010年5月26日
/****************************************************/
function gvUsers_onmouseout(listId, SelectRadioID, row) {
var SelectRadio = document.getElementById(SelectRadioID);
//找到控制范圍
var GridViewtableSearchList = document.getElementById(listId);
//找到控制范圍下所有input
var objs = GridViewtableSearchList.getElementsByTagName("input");
//找到控制范圍下所有checkbox并都變為false
for (var i = 0; i < objs.length; i++) {
if (objs[i].type.toLowerCase() == "checkbox" && objs[i] == SelectRadio) {
if (SelectRadio.checked) {
//設置選中行的顏色
row.style.backgroundColor = '#33A922'
}
else {
//設置交替行的顏色
if (i % 2 == 0) {
row.style.backgroundColor = '#FFFFFF'
}
else {
row.style.backgroundColor = '#F4FAFD'
}
}
}
}
}
/****************************************************/
//功能:鼠標單擊時使用
//說明:onmouseout事件時使用
//作者:XXXXXX
//日期:2010年5月26日
/****************************************************/
function SelectRadio(listId, SelectRadioID, rv, row) {
var SelectRadio = document.getElementById(SelectRadioID);
//找到控制范圍
var GridViewtableSearchList = document.getElementById(listId);
//找到控制范圍下所有input
var objs = GridViewtableSearchList.getElementsByTagName("input");
//找到控制范圍下所有checkbox并都變為false
for (var i = 0; i < objs.length; i++) {
//設置除當前選擇行外其它行的背景色
if (objs[i].type.toLowerCase() == "checkbox" && objs[i] != SelectRadio) {
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 鞍山市| 温州市| 舟曲县| 平武县| 元朗区| 南溪县| 大足县| 清徐县| 甘孜县| 濮阳市| 彭州市| 无棣县| 方正县| 涡阳县| 宜丰县| 饶阳县| 新巴尔虎右旗| 涟水县| 巨鹿县| 莱州市| 乌鲁木齐市| 青海省| 海林市| 邢台县| 乌拉特中旗| 永德县| 平罗县| 武强县| 台北市| 宁夏| 大方县| 特克斯县| 丽江市| 丹巴县| 怀来县| 临沂市| 来宾市| 翁牛特旗| 江安县| 镇远县| 驻马店市|