现在我有个grildview 帮定一列,我想点击一行,这行颜色变掉,其余颜色还原。 e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#ffe300'");这样写的话,不会还原,请问怎么写?
解决方案 »
- 如何把sqlserver数据导入到access
- asp.net中如何实现多语言???
- ActiveX控件 和ActiveX插件 区别
- 用microsoft visual 2003 怎样开发wap网站呀
- 高手帮忙,为什么设好虚拟目录之后在.net中就看不到了!!!!
- 进来看看这个存储过程怎么没有返回值呢
- 高难问题。气死我啦!有请高手
- “索引超出范围。必须为非负值并小于集合大小。参数名:index”,请问原因???
- 为什么.aspx页传递querystring至另一.asp页不行?
- oledbdataadapter参数问题?
- showModaldialog()中url直接用ip地址的问题
- ASP.NET2.0 .aspx页面生成.html页面
-cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Default8 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = GenerateTable();
GridView1.DataBind();
} private DataTable GenerateTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Products", typeof(string));
dt.Columns.Add("Price", typeof(decimal));
DataRow row;
Random rnd = new Random();
for (int i = 1; i != 31; ++i)
{
row = dt.NewRow();
row[0] = i;
row[1] = "Product_" + i;
row[2] = Math.Round(rnd.Next(20, 100) / 1.48D, 2);
dt.Rows.Add(row);
}
return dt;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#ffe300';onRowClick(this)");
}
}
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>
</div>
</form>
<script type="text/javascript">
function onRowClick(srcRow){
var rows=document.getElementById("<%=GridView1.ClientID %>").rows;
for(var i=0;i!=rows.length;++i)
rows[i].style.backgroundColor="#fff";
srcRow.style.backgroundColor="#ffe300";
}
</script>
</body>
</html>