gpt4 book ai didi

asp.net - 当前上下文中不存在名称 'GridView1'

转载 作者:行者123 更新时间:2023-12-02 12:07:49 25 4
gpt4 key购买 nike

我有两个名为 TimeSheet.aspx.cs 和 TimSheet.aspx 的文件,下面给出了文件的代码供您引用。

当我构建应用程序时,我收到错误“名称'GridView1'在当前上下文中不存在”,即使我有一个ID为GridView1的控件并且我也添加了runat =“server”。

我无法弄清楚是什么导致了这个问题。任何人都可以弄清楚这里发生了什么。

感谢和问候,

=======================================
TimeSheet.aspx.cs
=======================================
#region Using directives
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSMS.Web.UI;
#endregion

public partial class TimeSheets: Page
{
protected void Page_Load(object sender, EventArgs e)
{

FormUtil.RedirectAfterUpdate(GridView1, "TimeSheets.aspx?page={0}");
FormUtil.SetPageIndex(GridView1, "page");
FormUtil.SetDefaultButton((Button)GridViewSearchPanel1.FindControl("cmdSearch"));
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string urlParams = string.Format("TimeSheetId={0}", GridView1.SelectedDataKey.Values[0]);
Response.Redirect("TimeSheetsEdit.aspx?" + urlParams, true);
}

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {


}
}
=======================================================
TimeSheet.aspx
=======================================================
<%@ Page Language="C#" Theme="Default" MasterPageFile="~/MasterPages/admin.master" AutoEventWireup="true" CodeFile="TimeSheets.aspx.cs" Inherits="TimeSheets" Title="TimeSheets List" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">Time Sheets List</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<data:GridViewSearchPanel ID="GridViewSearchPanel1" runat="server" GridViewControlID="GridView1" PersistenceMethod="Session" />
<br />
<data:EntityGridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
DataSourceID="TimeSheetsDataSource"
DataKeyNames="TimeSheetId"
AllowMultiColumnSorting="false"
DefaultSortColumnName=""
DefaultSortDirection="Ascending"
ExcelExportFileName="Export_TimeSheets.xls" onrowcommand="GridView1_RowCommand"
>
<Columns>
<asp:CommandField ShowSelectButton="True" ShowEditButton="True" />
<asp:BoundField DataField="TimeSheetId" HeaderText="Time Sheet Id" SortExpression="[TimeSheetID]" ReadOnly="True" />
<asp:BoundField DataField="TimeSheetTitle" HeaderText="Time Sheet Title" SortExpression="[TimeSheetTitle]" />
<asp:BoundField DataField="StartDate" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Start Date" SortExpression="[StartDate]" />
<asp:BoundField DataField="EndDate" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="End Date" SortExpression="[EndDate]" />
<asp:BoundField DataField="DateOfCreation" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Date Of Creation" SortExpression="[DateOfCreation]" />
<data:BoundRadioButtonField DataField="Locked" HeaderText="Locked" SortExpression="[Locked]" />
<asp:BoundField DataField="ReviewedBy" HeaderText="Reviewed By" SortExpression="[ReviewedBy]" />
<data:HyperLinkField HeaderText="Employee Id" DataNavigateUrlFormatString="EmployeesEdit.aspx?EmployeeId={0}" DataNavigateUrlFields="EmployeeId" DataContainer="EmployeeIdSource" DataTextField="LastName" />

</Columns>
<EmptyDataTemplate>
<b>No TimeSheets Found!</b>
</EmptyDataTemplate>
</data:EntityGridView>
<asp:GridView ID="GridView2" runat="server">
</asp:GridView>
<br />
<asp:Button runat="server" ID="btnTimeSheets" OnClientClick="javascript:location.href='TimeSheetsEdit.aspx'; return false;" Text="Add New"></asp:Button>
<data:TimeSheetsDataSource ID="TimeSheetsDataSource" runat="server"
SelectMethod="GetPaged"
EnablePaging="True"
EnableSorting="True"
EnableDeepLoad="True"
>
<DeepLoadProperties Method="IncludeChildren" Recursive="False">
<Types>
<data:TimeSheetsProperty Name="Employees"/>
<%--<data:TimeSheetsProperty Name="TimeSheetDetailsCollection" />--%>
</Types>
</DeepLoadProperties>
<Parameters>
<data:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" />
<data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />
<asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex" Type="Int32" />
<asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize" Type="Int32" />
<data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />
</Parameters>
</data:TimeSheetsDataSource>

</asp:Content>

最佳答案

问题可能是 GridView1 没有自动添加到 Designer.cs 文件中。如果是这种情况,请手动将其添加到设计器中。

关于asp.net - 当前上下文中不存在名称 'GridView1',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2073738/

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