gpt4 book ai didi

javascript - 类型 'System.Web.UI.WebControls.GridView' 没有名为 'script' 的公共(public)属性

转载 作者:行者123 更新时间:2023-11-30 16:37:26 27 4
gpt4 key购买 nike

这是我的 aspx 代码。简单地说,它有一个 gridview,我想添加一些 javascipt 代码。

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="MainForm.aspx.cs" 
Inherits="GUI_MainForm" EnableSessionState="True" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
<div style="float:left">
<asp:Label runat="server" ID="label1"></asp:Label>
</div>
<div style="float:right">
<asp:GridView ID="gridviewFriend" Width="200px" runat="server" BorderStyle="None" ShowHeader="False" OnRowDataBound ="gridviewFriendRowDataBound">
<script type="text/javascript" >
function onMouseOver(rowIndex) {
var gv = document.getElementById("gridviewFriend");
var rowElement = gv.rows[rowIndex];
rowElement.style.backgroundColor = "#c8e4b6";
rowElement.cells[1].style.backgroundColor = "green";
}

function onMouseOut(rowIndex) {
var gv = document.getElementById("gridviewFriend");
var rowElement = gv.rows[rowIndex];
rowElement.style.backgroundColor = "#fff";
rowElement.cells[1].style.backgroundColor = "#fff";
}
</script>
</asp:GridView>
</div>
</asp:Content>

我不知道为什么当我插入一些javascript代码时,它显示错误:

Type System.Web.UI.WebControls.GridView does not have a public property named script

.

最佳答案

请删除 script 标签并在您的 RowDataBound 事件中执行此操作。

protected void gridviewFriendRowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#c8e4b6';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#fff';");
}
}

框架是你的 friend !

关于javascript - 类型 'System.Web.UI.WebControls.GridView' 没有名为 'script' 的公共(public)属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32515752/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com