System.Data.DataRowView' 不包含名称为 'State' 的 属性

System.Data.DataRowView' does not contain a property with the name 'State'

<asp:GridView ID="dgvCustomers" runat="server" AutoGenerateColumns="False" HorizontalAlign="Center" DataKeyNames="ID" DataSourceID="dsCustomerTickets" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" OnRowUpdated="dgvCustomers_RowUpdated">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:CommandField EditImageUrl="~/svg/edit.png" UpdateImageUrl="~/svg/save.png" CancelImageUrl="~/svg/cancel.png" ButtonType="Image" ShowEditButton="True" />
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:BoundField DataField="System" HeaderText="System" SortExpression="System" />
                <asp:BoundField DataField="LoggedDate" HeaderText="LoggedDate" SortExpression="LoggedDate" />
                <asp:BoundField DataField="ClosedDate" HeaderText="ClosedDate" SortExpression="ClosedDate" />
                <asp:BoundField DataField="Resolution" HeaderText="Resolution" SortExpression="Resolution" />
                <%--<asp:BoundField DataField="HistoryID" HeaderText="HistoryID" SortExpression="HistoryID" />--%>
                <%--<asp:BoundField DataField="Priority" HeaderText="Priority" SortExpression="Priority" />--%>
                <asp:BoundField DataField="LoggedBy" HeaderText="LoggedBy" SortExpression="LoggedBy" />
                <asp:TemplateField HeaderText="State" SortExpression="State2">
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlstate" runat="server" DataSourceID="SqlDataSource2" DataTextField="State" DataValueField="ID" SelectedValue='<%# Bind("State") %>' AppendDataBoundItems="true">
                            <asp:ListItem Text="Select a State" Value="" />
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("State2") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Priority" SortExpression="State3">
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlpriority" runat="server" DataSourceID="SqlDataSource3" DataTextField="Priority" DataValueField="ID" SelectedValue='<%# Bind("Priority") %>' AppendDataBoundItems="true">
                            <asp:ListItem Text="Select Priority" Value="" />
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("State3") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#CCCC99" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#F7F7DE" />
            <SelectedRowStyle BackColor="#0099ff" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FBFBF2" />
            <SortedAscendingHeaderStyle BackColor="#848384" />
            <SortedDescendingCellStyle BackColor="#EAEAD3" />
            <SortedDescendingHeaderStyle BackColor="#575357" />
        </asp:GridView>
        <asp:SqlDataSource ID="dsCustomerTickets" runat="server" ConnectionString="<%$ ConnectionStrings:TicketsSupportConnectionString %>" DeleteCommand="DELETE FROM [Tickets] WHERE [ID] = @ID" InsertCommand="INSERT INTO [Tickets] ([Title], [Description], [System], [LoggedDate], [ClosedDate], [Resolution], [Priority], [HistoryID], [LoggedBy], [State]) VALUES (@Title, @Description, @System, @LoggedDate, @ClosedDate, @Resolution, @Priority, @HistoryID, @LoggedBy, @State)" SelectCommand="SELECT T.ID, T.Title, T.Description, T.System, T.Attachments, T.LoggedDate, T.ClosedDate, T.Resolution, T.Priority, T.LoggedBy, S.State AS State2, p.Priority AS State3 FROM Tickets AS T INNER JOIN State AS S ON T.State = S.ID INNER JOIN Priority AS p ON T.Priority = p.ID WHERE (T.LoggedBy = @LoggedBy)" UpdateCommand="UPDATE Tickets SET Description = @Description, System = @System, ClosedDate = @ClosedDate, Resolution = @Resolution, Priority = @Priority, HistoryID = @HistoryID, State = @State WHERE (ID = @ID)">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="System" Type="String" />
                <asp:Parameter Name="LoggedDate" Type="DateTime" />
                <asp:Parameter Name="ClosedDate" Type="DateTime" />
                <asp:Parameter Name="Resolution" Type="String" />
                <asp:Parameter Name="Priority" Type="Int32" />
                <asp:Parameter Name="HistoryID" Type="Int32" />
                <asp:Parameter Name="LoggedBy" Type="String" />
                <asp:Parameter Name="State" Type="Int32" />
            </InsertParameters>
            <SelectParameters>
                <asp:QueryStringParameter Name="LoggedBy" QueryStringField="u" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="System" Type="String" />
                <asp:Parameter Name="ClosedDate" Type="DateTime" />
                <asp:Parameter Name="Resolution" Type="String" />
                <asp:Parameter Name="Priority" Type="Int32" />
                <asp:Parameter Name="HistoryID" Type="Int32" />
                <asp:Parameter Name="State" Type="Int32" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TicketsSupportConnectionString %>" SelectCommand="SELECT [ID],[State] FROM [dbo].[State]"></asp:SqlDataSource>

使用上面的代码,我不断收到错误消息。 在 SQL 中,如果我 运行 SqlDataSource2 查询我得到结果(ID 和状态)。

我尝试更改我的查询并在查询生成器中编辑我拖动的 SqlDataSource2。 单击命令字段 "EditImageUrl" 后,我立即收到上述错误。 也许我正在查看我的代码太久没有注意到任何问题。

我用谷歌搜索了它,但没有找到类似的东西: 我看过 Here 和这里一样,我在下拉列表中使用 bind 而不是 Eval。

我还尝试将我的 sqldatasource 更改为:

  1. Select * 来自州
  2. Select ID,来自州的州
  3. Select ID,来自 dbo.State
  4. 的州

我们将不胜感激。

编辑和更新

EditTemplate 中,您将 SqlDataSource2 中的 aspDropDown 填入正确的 DataTextField="State" DataValueField="ID"。但是 SelectedValue 属于 <asp:SqlDataSource ID="dsCustomerTickets"。因此,您需要 SelectCommand 中的 T.State 才能使绑定 SelectedValue='<%# Bind("State") %>' 正确。 ItemTemplate 中的 Bind 也没有必要。 Eval("State2") 够了。
第一个 SqlDataSource 应该是

    <asp:SqlDataSource ID="dsCustomerTickets" runat="server" 
        ConnectionString="<%$ ConnectionStrings:TicketsSupportConnectionString %>" 
        DeleteCommand="DELETE FROM [Tickets] WHERE [ID] = @ID" 
        InsertCommand="INSERT INTO [Tickets] (/*removed for shortness*/ [State]) VALUES ( @State2)" 
        SelectCommand="SELECT /*your list*/ T.State, S.State AS State2, p.Priority AS State3 FROM Tickets AS T INNER JOIN State AS S ON T.State = S.ID INNER JOIN Priority AS p ON T.Priority = p.ID WHERE (T.LoggedBy = @LoggedBy)" 
        UpdateCommand="UPDATE Tickets SET /*removed for shortness*/ State = @State2 WHERE (ID = @ID)">
        <DeleteParameters>
            <asp:Parameter Name="ID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <%--your parameters removed for shortness--%>
            <asp:Parameter Name="State" Type="Int32" />
        </InsertParameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="LoggedBy" QueryStringField="u" />
        </SelectParameters>
        <UpdateParameters>
            <%--your parameters removed for shortness--%>
            <asp:Parameter Name="State" Type="Int32" />
            <asp:Parameter Name="ID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>