最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

js实现GridView单选效果自动设置交替行、选中行、鼠标移动行背景色_javascript技巧

来源:动视网 责编:小采 时间:2020-11-27 20:49:38
文档

js实现GridView单选效果自动设置交替行、选中行、鼠标移动行背景色_javascript技巧

js实现GridView单选效果自动设置交替行、选中行、鼠标移动行背景色_javascript技巧:后台代码 代码如下: /// /// 数据行绑定事件 /// /// /// protected void gvProduct_RowDataBound(object sender, GridViewRowEventArgs e) { try { if (e.Row.RowType == DataControlRowType.Dat
推荐度:
导读js实现GridView单选效果自动设置交替行、选中行、鼠标移动行背景色_javascript技巧:后台代码 代码如下: /// /// 数据行绑定事件 /// /// /// protected void gvProduct_RowDataBound(object sender, GridViewRowEventArgs e) { try { if (e.Row.RowType == DataControlRowType.Dat


后台代码
代码如下:
///
/// 数据行绑定事件
///

///
///
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) {
objs[i].checked = false;
//设置交替行的背景色
if (i % 2 == 0) {
objs[i].parentElement.parentElement.style.backgroundColor = '#FFFFFF'
}
else {
objs[i].parentElement.parentElement.style.backgroundColor = '#F4FAFD'
}
}
}
var SelectRadioSelectRadioID = SelectRadio.id;
SelectRadio.checked = !SelectRadio.checked
//设置当前选择行的背景色和返回选择行的主键
if (SelectRadio.checked) {
row.style.backgroundColor = '#33A922'
window.returnValue = rv;
}
else {
window.returnValue = ""
}
}

文档

js实现GridView单选效果自动设置交替行、选中行、鼠标移动行背景色_javascript技巧

js实现GridView单选效果自动设置交替行、选中行、鼠标移动行背景色_javascript技巧:后台代码 代码如下: /// /// 数据行绑定事件 /// /// /// protected void gvProduct_RowDataBound(object sender, GridViewRowEventArgs e) { try { if (e.Row.RowType == DataControlRowType.Dat
推荐度:
标签: 鼠标 选择 效果
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top