鼠标点击GridView某一行时改变该行的背景色方法
鼠标点击GridView某一行时改变该行的背景色方法--------------------编程问答-------------------- //选定GridView行
function selectArow(sObject,TableName)
{
var TN=eval("document.all."+TableName);
for(var i=0;i <TN.rows.length;i++)
TN.rows(i).bgColor=0xffffff;
sObject.bgColor=0xEEFFFF;
}
然后在RowDataBound事件里写
e.Row.Attributes.Add("onclick","javascript:selectArow(this, "GridView1 ");"); --------------------编程问答-------------------- 楼上的
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onclick","javascript:selectArow(this,"GridView1");");
}
Js调用不了~~
怎么改改?? --------------------编程问答-------------------- 你要加一个判断:
if (e.Row.RowType==DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick","javascript:selectArow(this,"GridView1");");
}
--------------------编程问答-------------------- 还是不行呢~~
"GridView1");");
提示应输入 ) --------------------编程问答-------------------- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
}
这个可以的 --------------------编程问答-------------------- 楼主,我写过的,明天给你代码! --------------------编程问答-------------------- 楼上的正解,呵呵我不用改了! --------------------编程问答--------------------
if (e.Row.RowType == DataControlRowType.DataRow)//modify by songxq:鼠标移动改变row的背景颜色--------------------编程问答-------------------- 楼上的看清楚是:鼠标点击,不是鼠标滑过! --------------------编程问答-------------------- e.Row.Attributes.Add("onclick","javascript:selectArow(this,'GridView1')");
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#e6dcff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
--------------------编程问答-------------------- 呵呵~
“jasonlee0927 ”的方法调试通过:整理如下
-----------------------------------------------------------
--------------------编程问答-------------------- 快揭贴给分啊,哈..... --------------------编程问答-------------------- 我试了一下,还是不行啊 --------------------编程问答-------------------- 我也试了一下 没有效果啊 --------------------编程问答-------------------- onmousedown --------------------编程问答-------------------- 做法:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick","javascript:selectArow(this, 'GridView1 ')");
}
}
双击GridView的OnRowDataBound事件;
在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
//执行循环,保证每条数据都可以更新
for (i = 0; i < GridView1.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标点击时更改背景色
e.Row.Attributes.Add("onclick", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
}
}
}
前台代码:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>实现鼠标划过改变GridView的行背景色 清清月儿http://blog.csdn.net/21aspnet </title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="身份证号码"
DataSourceID="SqlDataSource1" AllowSorting="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Font-Size="12px" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="身份证号码" HeaderText="身份证号码" ReadOnly="True" SortExpression="身份证号码" />
<asp:BoundField DataField="姓名" HeaderText="姓名" SortExpression="姓名" />
<asp:BoundField DataField="家庭住址" HeaderText="家庭住址" SortExpression="家庭住址" />
<asp:BoundField DataField="邮政编码" HeaderText="邮政编码" SortExpression="邮政编码" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:北风贸易ConnectionString1 %>"
SelectCommand="SELECT top 5 [身份证号码], [姓名], [员工性别], [家庭住址], [邮政编码] FROM [飞狐工作室]" DataSourceMode="DataReader"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
--------------------编程问答-------------------- 这么明了,还不结帖。。。。。。。。。 --------------------编程问答-------------------- 想要脚本的还是后台的啊!!!
后台就
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick","javascript:selectArow(this, 'GridView1 ')");
}
}
脚本就
$("#table1 tr:not(:first)").click(function () {--------------------编程问答-------------------- 清清月儿的72大绝技里有
$(this).css("backgroundColor", "#FFF");
});
补充:.NET技术 , ASP.NET