if (e.Row.RowType == DataControlRowType.DataRow)
e.Row.Attributes.Add("onclick", "this.style.backgroundColor=this.style.backgroundColor=='#000000'?'#ebebce':'#000000';");
}
这段代码问了不少地方 代码本身没问题
点击第一次是正常的 不知道为什么 点击第二次的时候没反映
求高手帮忙看下 用的VS2010 控件GridView显示 事件RowDataBound
(怨念啊!今天弄这东西弄了一整天了!)
解决方案 »
- 网站在本机发布正常运行 发布到服务器上 JS不执行 急急
- crystalreportviewer 在Page_load中读一个报表文档显示,出现问题?
- jquery dialog的关闭事件
- 如何在GridView中限制显示字数?
- 关于return的 ....
- 初学VS.net,用C#做了一个asp.net的网站,如何发布到服务器上?
- 大家帮忙看看,怎样才能把这个参数传递过去?谢谢!
- 关于在listbox中改变顺序的问题
- 服务器端与客户端之间实现模拟复制粘贴, 有什么办法吗?
- mvc模式下获取到easyui的datagrid的数据后,传到后台怎么接受?
- 在线等—服务器系统日志中这样的错误,应该怎样排除
- 一般处理程序返回JS的问题
var lastRow = null;function RowSelected(rowID)
{
var row = document.getElementById(rowID);
if(lastRow == null)
{
lastColor = row.style.backgroundColor;
lastRow = row;
row.style.backgroundColor = 'PeachPuff';
}
else
{
if(lastRow == row) return;
lastRow.style.backgroundColor = lastColor;
lastColor = row.style.backgroundColor;
lastRow = row;
row.style.backgroundColor = 'PeachPuff';
}
}</script> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
e.Row.Attributes.Add("onclick", "RowSelected('" + e.Row.ClientID + "')");//点击行变色
}
}
} 方法二 JS代码:<script type="text/javascript"> var prevselitem=null;
function selectx(row)
{
if(prevselitem!=null)
{
prevselitem.style.backgroundColor='#ffffff';
}
row.style.backgroundColor='PeachPuff';
prevselitem=row;
}</script> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)";);//点击行变色
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow){
e.Row.Attributes.Add("onclick", "myfunction(this);");
}
}<script type="text/javascript">
var color = ["#000000", "#ebebce"];
function myfunction(o) {
i = parseInt(o.getAttribute("click"));
if (isNaN(i)) i = 1;
o.style.backgroundColor = color[i % 2];
o.setAttribute("click", ++i);
}
</script>