【发布时间】:2023-03-31 17:10:01
【问题描述】:
当用户在行中切换并获得焦点并失去焦点时,我正在尝试更改 gridview 中行的背景颜色。
我能够改变标签的前景色,(只是在测试这个)所以我相信它可以做到。
我需要帮助编写将捕获表行的两个标题的 ClientID 的 javascript。
它可能看起来像:document.getElementById("
但我相信您必须先定义网格,然后再定义 LinkButton。不知道如何做这部分。
我下面的代码将更改标签前景色,请记住我想更改标题和项目模板的背景色。
感谢所有帮助。
这是我的代码:
<script type="text/javascript">
function setheaderfocus() {
document.getElementById("<%=Label1.ClientID %>").style.color = "Red"; //works
}
function setheaderblur() {
document.getElementById("<%=Label1.ClientID %>").style.color = "Blue"; //works
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>GridView Select Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Test" ></asp:Label>
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:LinkButton ID="Button2" runat="server"
onfocus="setheaderfocus()"
onblur="setheaderblur()"
Text="New" />
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="Button1" runat="server"
onfocus="setrowfocus()"
onblur="setrowblur()"
Text="Edit" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<asp:sqldatasource id="YourSource"
selectcommand="SELECT * FROM "TBL_YOUR_DATA""
connectionstring="<%$ ConnectionStrings:ConnectionString %>"
runat="server" ProviderName="<%$ YOUR_PROVIDER %>"/>
</form>
</body>
</html>
【问题讨论】:
标签: javascript asp.net gridview focus highlight