C# C GridView上的编辑错误

C# C GridView上的编辑错误,c#,asp.net,gridview,C#,Asp.net,Gridview,以下是我的GridView: <div> <asp:GridView ID="MainGridView" runat="server" AllowPaging="True" DataSourceID="GridViewDataSource" EnableModelValidation="True" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" onpa

以下是我的GridView:

<div>
<asp:GridView ID="MainGridView" runat="server" AllowPaging="True" DataSourceID="GridViewDataSource" EnableModelValidation="True" CssClass="mGrid" PagerStyle-CssClass="pgr" 
        AlternatingRowStyle-CssClass="alt" onpageindexchanging="MainGridView_PageIndexChanging">
<Columns>
    <asp:CommandField ButtonType="Image" CancelImageUrl="~/images/icon_cancel.jpg" EditImageUrl="~/images/icon_edit.jpg" ShowEditButton="True" UpdateImageUrl="~/images/icon_update.jpg" />
</Columns>
</asp:GridView>
    <asp:ObjectDataSource ID="GridViewDataSource" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByCategory" 
    TypeName="SEPTA_DSTableAdapters.AgencyTBLTableAdapter">
        <SelectParameters>
            <asp:SessionParameter DefaultValue="" Name="Category" SessionField="Cat" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
</div>
当我在两个单独的下拉列表之间进行选择时,我的GridView会更改属性

<tr><td>File Name<br /><asp:DropDownList ID="FileTypeDDL" runat="server" 
        Width="136" onselectedindexchanged="FileTypeDDL_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Agency" Value="Agency" />
<asp:ListItem Text="Calendar" Value="Calendar" />
<asp:ListItem Text="Calendar Dates" Value="Calendar Dates" />
<asp:ListItem Text="Routes" Value="Routes" />
<asp:ListItem Text="Stop Times" Value="Stop Times" />
<asp:ListItem Text="Stops" Value="Stops" />
<asp:ListItem Text="Transfers" Value="Transfers" />
<asp:ListItem Text="Trips" Value="Trips" />
</asp:DropDownList></td></tr>

<tr><td>Category<br /><asp:DropDownList ID="CategoryDDL" runat="server" Width="136" onselectedindexchanged="CategoryDDL_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Select" Value="Select" />
<asp:ListItem Text="Regional Rail" Value="Regional Rail" />
<asp:ListItem Text="Transit" Value="Transit" />
</asp:DropDownList></td></tr>
问题:

为什么它不在站点下工作,但在代理下工作? 代码背后是否缺少一个组件

以下是我的数据表:


我相信如果你看看你的数据源SQL数据库?我不确定。。。在AgencyTBLTableAdapter后面的某个地方,您将看到该表有一个名为AgencyID的列

但是,当您查看类似的Stops表时,我猜您不会找到StopsID

需要修改备份数据源以使其具有StopsID


如果可以,请提供有关TableAdapters后面的数据表的更多信息。

在GridView中使用标准编辑按钮时,必须将函数添加到页面加载中,如下所示


如果有人知道比把这些行放在各处更好的修复方法,我洗耳恭听。

我在SQL Server的数据集中有两个表。最初的GridView加载Agency表,但如果从DropDownList中选择了不同的项,我会在代码中专门放置一个不同的数据源。
<tr><td>File Name<br /><asp:DropDownList ID="FileTypeDDL" runat="server" 
        Width="136" onselectedindexchanged="FileTypeDDL_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Agency" Value="Agency" />
<asp:ListItem Text="Calendar" Value="Calendar" />
<asp:ListItem Text="Calendar Dates" Value="Calendar Dates" />
<asp:ListItem Text="Routes" Value="Routes" />
<asp:ListItem Text="Stop Times" Value="Stop Times" />
<asp:ListItem Text="Stops" Value="Stops" />
<asp:ListItem Text="Transfers" Value="Transfers" />
<asp:ListItem Text="Trips" Value="Trips" />
</asp:DropDownList></td></tr>

<tr><td>Category<br /><asp:DropDownList ID="CategoryDDL" runat="server" Width="136" onselectedindexchanged="CategoryDDL_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="Select" Value="Select" />
<asp:ListItem Text="Regional Rail" Value="Regional Rail" />
<asp:ListItem Text="Transit" Value="Transit" />
</asp:DropDownList></td></tr>
 DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'StopsID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'StopsID'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'StopsID'.]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +8660309
   System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2178
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +22
   System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e) +17
   System.Web.UI.Control.PreRenderRecursiveInternal() +80
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
protected void Page_Load(object sender, EventArgs e)
    {
        if (FileTypeDDL.SelectedValue == "Agency") { AgencyGrid(); }
        else if (FileTypeDDL.SelectedValue == "Stops") { StopsGrid(); }
    }