需求:使用鼠标,选中gridview绑定数据表的一行,该行的底色会改变。
解决方案 »
- 更新库存问题
- 有了SqlDataSource,还需要ORM吗?跟ORM说byebye吧。
- url重写和生成静态页面问题 急求回答!!
- C# ASP.net关于制作OA的登陆问题
- eclipse开发struts的最简单的问题。
- 如何做定时关机程序???
- 关于参数传递的问题
- 请whn801213 (新被子) 和chieftech进来解释一下怎么回事
- 页面上的图片是动态显示的,移动上时,弹出一个图层,图层有很多超链接的记录,点击打开时,转到相应的界面?
- 水晶报表时什么东西,最近在论坛中总是看到这个东东,那位大哥给解释一下,有没有系统的讲解水晶报表的文章??
- 如何调用word
- asp.net调用Remoting的问题
GridView 72 绝技
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentColor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentColor");
}
}
{
var p=obj.parentNode;
for(i=0;i<p.rows.length;i++)
{
p.rows[i].style.backgroundColor="white";
}
obj.style.backgroundColor="red";
}
</script>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick","test(this)");
}
}
<asp:GridView runat="server" >
<SelectedRowStyle BackColor="#FFFFCC" />
...
<link href="CSS/style.css" rel="stylesheet" type="text/css" />
<script src="JS/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"> <script type="text/javascript">
var allID = "";
function checkJs(IsCheck) {
allID = ""
if (IsCheck) {
$("#gv_info tr:gt(0)").css("background", "#cfffff");
$("#gv_info tr:gt(0)").each(function() {
$(this).find(":checkbox").attr("checked", true);
allID += $(this).find(":checkbox").val()+",";
})
} else {
$("#gv_info tr").css("background", "");
$("#gv_info tr:gt(0)").each(function() {
$(this).find(":checkbox").attr("checked", false);
allID = "";
})
$("#hdID").val(allID);
}
} $(function() {
var flag = 0;
$("#gv_info tr:gt(0)").click(function() {
flag = 0;
var thirdRe = "";
thirdRe = $(this).find(":checkbox").val() + ",";
if ($(this).css("background") == "#cfffff") {
$(this).css("background", "");
$(this).find(":checkbox").attr("checked", false);
allID = allID.replace(thirdRe, '');
} else {
$(this).css("background", "#cfffff");
$(this).find(":checkbox").attr("checked", true);
allID += thirdRe;
}
$("#gv_info tr:gt(0)").each(function() {
if ($(this).css("background") != "#cfffff") {
flag = flag + 1;
}
})
if (flag == 0) {
$("#gv_info tr:eq(0)").find(":checkbox").attr("checked", true);
} else {
$("#gv_info tr:eq(0)").find(":checkbox").attr("checked", false);
}
$("#hdID").val(allID); $("<h2>我的" + flag + "</h2>").appendTo("h1"); }) })
</script> <title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="div" align="center">
<asp:HiddenField ID="hdID" runat="Server" />
<asp:GridView ID="gv_info" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<input type='checkbox' id='chkAll' name='chkAll' onclick='checkJs(this.checked);' />
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" Width="60px" />
<ItemTemplate>
<input type="checkbox" id="chkSelect" name="chkSelect" value='<%# Eval("Col") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="id">
<ItemTemplate>
<asp:Label ID="Label1" Text='<% #Eval("Col") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="name">
<ItemTemplate>
<asp:Label ID="Label2" Text='<% #Eval("PID") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string constring = "Data Source=.;Initial Catalog=Test;User ID=sa;Password=";
SqlConnection con = new SqlConnection(constring);
string selectstring="SELECT top 10 * FROM tb";
SqlDataAdapter sds = new SqlDataAdapter(selectstring, con);
DataSet ds = new DataSet();
sds.Fill(ds);
gv_info.DataSource = ds.Tables[0];
gv_info.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
string a = hdID.Value;
}
}