Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Data.DataRowView“”不包含名为“State”的属性_C#_Sql_Asp.net_Gridview_Dropdown - Fatal编程技术网

C# System.Data.DataRowView“”不包含名为“State”的属性

C# System.Data.DataRowView“”不包含名为“State”的属性,c#,sql,asp.net,gridview,dropdown,C#,Sql,Asp.net,Gridview,Dropdown,通过上面的代码,我不断地得到错误。 在SQL中,如果我运行SqlDataSource2查询,我会得到结果ID和状态。 我尝试在查询生成器中更改查询并编辑拖动的SqlDataSource2。 我一单击commandfield EditImageUrl,就得到了上面的错误。 也许我正在查看我的代码,希望能注意到任何问题 我已经在谷歌上搜索过了,但没有看到像这样的东西: 我看过 这里也是一样,我在下拉列表中使用bind而不是Eval 我还尝试将sqldatasource更改为: 从状态选择* 从状态

通过上面的代码,我不断地得到错误。 在SQL中,如果我运行SqlDataSource2查询,我会得到结果ID和状态。

我尝试在查询生成器中更改查询并编辑拖动的SqlDataSource2。 我一单击commandfield EditImageUrl,就得到了上面的错误。 也许我正在查看我的代码,希望能注意到任何问题

我已经在谷歌上搜索过了,但没有看到像这样的东西: 我看过 这里也是一样,我在下拉列表中使用bind而不是Eval

我还尝试将sqldatasource更改为:

从状态选择* 从状态中选择ID、状态 从dbo.State中选择ID、State 任何帮助都将不胜感激。

编辑和更新 在EditTemplate中,使用正确的DataTextField=State DataValueField=ID从SqlDataSource2填写aspDropDown。但SelectedValue属于
<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>
    <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>