C# GridView RowDataBoundEvent未运行
我正在使用GridView,并使用TableAdapter与我的SQL Server 2017 Express通信。我已成功地将表显示到GridView中,但我希望数据库中每个条目的名称都有一个超链接,该超链接将用户指向另一个页面,该页面包含允许用户编辑相应条目的DetailsView。但是,我目前对RowDataBoundEvent有问题,因为它似乎没有触发 当我在if语句上设置一个断点时,程序将运行 我检查了我的RowDataBound方法名称,它与我在aspx文件中指定的名称匹配:C# GridView RowDataBoundEvent未运行,c#,asp.net,visual-studio,gridview,tableadapter,C#,Asp.net,Visual Studio,Gridview,Tableadapter,我正在使用GridView,并使用TableAdapter与我的SQL Server 2017 Express通信。我已成功地将表显示到GridView中,但我希望数据库中每个条目的名称都有一个超链接,该超链接将用户指向另一个页面,该页面包含允许用户编辑相应条目的DetailsView。但是,我目前对RowDataBoundEvent有问题,因为它似乎没有触发 当我在if语句上设置一个断点时,程序将运行 我检查了我的RowDataBound方法名称,它与我在aspx文件中指定的名称匹配: <
<asp:GridView ID="ProductView" runat="server" Height="299px" Width="578px" AllowPaging="True" HorizontalAlign="Center"
OnRowDataBoundEvent="ProductViewRowBound" style="table-layout:auto">
<HeaderStyle Width="300px" />
</asp:GridView>
ASPX文件:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Maintenance.aspx.cs" Inherits="Maintenance" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div style="overflow-x:scroll;overflow-y:scroll; margin-left:auto; margin-right:auto;">
<asp:GridView ID="ProductView" runat="server" Height="299px" Width="578px" AllowPaging="True" HorizontalAlign="Center"
OnRowDataBoundEvent="ProductViewRowBound" style="table-layout:auto">
<HeaderStyle Width="300px" />
</asp:GridView>
</div>
</asp:Content>
为什么我的RowDataBoundEvent没有运行?我可以做些什么来修复它?首先,
OnRowDataBoundEvent
不存在。它应该是GridView中的OnRowDataBound
<asp:GridView ID="ProductView" runat="server" OnRowDataBound="ProductViewRowBound">
接下来,您将从代码隐藏中将正确的方法绑定到GridView,但是在您将数据绑定到GridView之后。因此,当您绑定productAdapter.GetData()
时,它将不起作用
因此,要么在GridView aspx中设置正确的事件名称,要么将方法绑定移到
ProductView.DataBind()上方代码>非常感谢。我没听懂!一切都按计划进行。真不敢相信我错过了。再次感谢你的帮助!
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Maintenance.aspx.cs" Inherits="Maintenance" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div style="overflow-x:scroll;overflow-y:scroll; margin-left:auto; margin-right:auto;">
<asp:GridView ID="ProductView" runat="server" Height="299px" Width="578px" AllowPaging="True" HorizontalAlign="Center"
OnRowDataBoundEvent="ProductViewRowBound" style="table-layout:auto">
<HeaderStyle Width="300px" />
</asp:GridView>
</div>
</asp:Content>
<asp:GridView ID="ProductView" runat="server" OnRowDataBound="ProductViewRowBound">