新手求助:GridView 的 backgroundcolor变色 无效

nxl801 2016-03-16 10:31:03

<html>
<script language="jscript" type="text/jscript">
function ClearAllTextBox() {
var obj = window.document.forms[0];
for (i = 0; i < obj.elements.length; i++) {
var elem = obj.elements[i];
if (elem) {
if (elem.type == "text") {
elem.value = "";
}
}
}
}
</script>
<head>

<title>项目管理</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="/Web/css/common.css"
type="text/css" />

</head>

<body>
<div id="man_zone">
<form id="engMachineForm" runat="server">
<input type="hidden" name="op" value="doLoadOne" />
<table width="70%" border="0" align="center" cellpadding="3"
cellspacing="1" class="table_style" >
<thead>
<tr>
<td class="left_title_header" colspan="2">
项目管理
</td>
</tr>
</thead>
<tbody>
<tr>
<td width="40%" class="left_title_2" style="text-align: center;">
项目编号
</td>
<td width="60%" class="left_title_2" style="text-align: left;">
<input type="text" id="txtBranchName" maxlength="10" value="" class="input_text" runat="server"/>
</td>
</tr>
</tbody>
<tfoot>
<tr bgcolor="#FFFFFF">
<td class="left_title_1" colspan="2"
style="text-align: left;padding-left:40%;">
<asp:Button ID="btnQuery" runat="server" Text="查询" CssClass="input_button" OnClick="btnQuery_Click" />
<input type="reset" value="清除" class="input_button" onclick="ClearAllTextBox">

</td>
</tr>
</tfoot>
</table>
<br />
<asp:GridView ID="gvProjInfo" CssClass="GridView" width="99%" border="0" cellpadding="3" cellspacing="1" BorderStyle="None" runat="server" AutoGenerateColumns="False" PageSize="6" AllowPaging="True" OnPageIndexChanging="gvProjInfo_PageIndexChanging" OnRowDataBound="gvProjInfo_RowDataBound">
<Columns>
<asp:BoundField DataField="First_kind_name" ItemStyle-Width="80px" HeaderText="项目编号" SortExpression="First_kind_name" >
<ItemStyle Width="80px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Customer_name" ItemStyle-Width="80px" HeaderText="客户名称" SortExpression="Customer_name" >
<ItemStyle Width="80px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="First_kind_CDate" ItemStyle-Width="100px" HeaderText="签约日期" SortExpression="First_kind_CDate" >
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="First_kind_DDate" ItemStyle-Width="100px" HeaderText="交货日期" SortExpression="First_kind_DDate" >
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="First_kind_SDate" ItemStyle-Width="100px" HeaderText="点火日期" SortExpression="First_kind_SDate" >
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="PM" ItemStyle-Width="80px" HeaderText="项目经理" SortExpression="PM" >
<ItemStyle Width="80px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Mech" ItemStyle-Width="180px" HeaderText="机械设计" SortExpression="Mech" >
<ItemStyle Width="180px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Elec" ItemStyle-Width="180px" HeaderText="电气设计" SortExpression="Elec" >
<ItemStyle Width="180px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Soft" ItemStyle-Width="180px" HeaderText="软件设计" SortExpression="Soft" >
<ItemStyle Width="180px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Stdtime" ItemStyle-Width="80px" HeaderText="标准工时" SortExpression="Stdtime" >
<ItemStyle Width="80px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Workhour" ItemStyle-Width="80px" HeaderText="已用工时" SortExpression="Workhour" >
<ItemStyle Width="80px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="descr" ItemStyle-Width="200px" HeaderText="项目描述" SortExpression="descr" >
<ItemStyle Width="200px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField>
<HeaderTemplate>
<input class="input_button" onclick="window.location = 'addOne.aspx'"
type="button" value="新增" />
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="linkEdit" runat="server" CommandArgument='<%# Eval("id") %>'
OnCommand="linkEdit_Command">编辑</asp:LinkButton>
<asp:LinkButton ID="linkDel" runat="server" CommandArgument='<%# Eval("id") %>' OnClientClick="return confirm('你确定要删除此用户吗?');" OnCommand="linkDel_Command" >删除</asp:LinkButton>
</ItemTemplate>
<HeaderStyle Width="80px" />
<ItemStyle Width="80px" />
</asp:TemplateField>
</Columns>
<PagerTemplate>
<table width="100%">
<tr>
<td align="right">
第<asp:Label ID="lblPageIndex" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>'></asp:Label>页
 共<asp:Label ID="lblPageCount" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageCount %>'></asp:Label>页
 每页<asp:Label ID="Label1" runat="server" Text='<%#((GridView)Container.Parent.Parent).PageSize %>'></asp:Label>条
 <asp:LinkButton Text="首页" ID="btnFirst" runat="server" CausesValidation="false"
CommandArgument="First" CommandName="Page" />
 <asp:LinkButton Text="上一页" ID="btnPre" runat="server" CausesValidation="false"
CommandArgument="Prev" CommandName="Page" />
 <asp:LinkButton Text="下一页" ID="btnNext" runat="server" CausesValidation="false"
CommandArgument="Next" CommandName="Page" />
 <asp:LinkButton Text="尾页" ID="btnLast" runat="server" CausesValidation="false"
CommandArgument="Last" CommandName="Page" />
</td>
</tr>
</table>
</PagerTemplate>
<PagerSettings PageButtonCount="5" Position="Bottom" Mode="NextPrevious"/>
<PagerStyle HorizontalAlign="Right"/>
</asp:GridView>
</form>
</div>
<p>
 </p>
</body>

</html>


protected void gvProjInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='yellow';");
}
}

onmouseover 变色没有效果。感觉tr样式被td覆盖了,怎么改呢?
...全文
225 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
nxl801 2016-03-17
  • 打赏
  • 举报
回复
引用 3 楼 sp1234 的回复:
asp.net 程序员应该学点 bootstrap,这样方便找工作。 要设置 table 的鼠标悬停背景色,首先,要去掉你自己的 GridView 的背景色设置(否则就覆盖了更高层的设置了),然后在你的 aspx 中引入 bootstrap,例如
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <link href="Content/bootstrap.css" rel="stylesheet" />
    <script src="Scripts/jquery-1.9.1.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
    <style>
        .table-hover > tbody > tr:hover {
            background-color: #ff00dc;
        }
    </style>

</head>
然后,在你的 GridView 上设置启用鼠标悬停功能
<asp:GridView ID="GridView1" runat="server" CssClass="table table-hover" ......
这就可以了。
非常感谢,我只是觉得好玩,学着玩玩的。我还是想知道我的程序的问题,简单的说,就是我的变色效果被gridview的cssclass覆盖了是嘛?
  • 打赏
  • 举报
回复
asp.net 前端开发最近10年 处于被微软遗忘的状态(微软只是去扯无用的 asp.net mvc 去了,忘记了最出彩的地方),所以,你应该学习最近5年涌现的前端技术和框架,而不要纠结在 asp.net 多年以前的一些方法。我们多年以前也并没有意识到 asp.net 会落后到如此。 考虑各种前端框架的是否精当、版本稳定兼容、不坑爹,那么 bootstrap 可以说是 asp.net 程序员必学必会的基础了。
  • 打赏
  • 举报
回复
asp.net 程序员应该学点 bootstrap,这样方便找工作。 要设置 table 的鼠标悬停背景色,首先,要去掉你自己的 GridView 的背景色设置(否则就覆盖了更高层的设置了),然后在你的 aspx 中引入 bootstrap,例如
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <link href="Content/bootstrap.css" rel="stylesheet" />
    <script src="Scripts/jquery-1.9.1.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
    <style>
        .table-hover > tbody > tr:hover {
            background-color: #ff00dc;
        }
    </style>

</head>
然后,在你的 GridView 上设置启用鼠标悬停功能
<asp:GridView ID="GridView1" runat="server" CssClass="table table-hover" ......
这就可以了。
nxl801 2016-03-17
  • 打赏
  • 举报
回复

<tr style="background-color: yellow;" onmouseover="this.style.backgroundColor='yellow';">

不是很懂 运行后 网页前台mouseover后的代码是这样的
bdmh 2016-03-16
  • 打赏
  • 举报
回复
js中会认得 this.style 吗,你看看style设置的语法

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧