Asp.net 编辑ListView项会返回“不能在DropDownList中选择多个项”。如果FormView处于编辑模式

Asp.net 编辑ListView项会返回“不能在DropDownList中选择多个项”。如果FormView处于编辑模式,asp.net,listview,drop-down-menu,formview,Asp.net,Listview,Drop Down Menu,Formview,我有一个FormView和一个ListView,我只想在FormView的EditITemTemplate中使用。但是,当我在编辑模式下单击ListView中的编辑或更新链接按钮时,页面错误:不能在DropDownList中选择多个项目。正如您在下面看到的,我已经从FormView中完全删除了ListView,如果FormView处于只读状态,ListView的功能将与预期的一样 <asp:SqlDataSource ID="SqlSource" runat="server

我有一个FormView和一个ListView,我只想在FormView的EditITemTemplate中使用。但是,当我在编辑模式下单击ListView中的编辑或更新链接按钮时,页面错误:不能在DropDownList中选择多个项目。正如您在下面看到的,我已经从FormView中完全删除了ListView,如果FormView处于只读状态,ListView的功能将与预期的一样

        <asp:SqlDataSource ID="SqlSource" runat="server" ConnectionString="<%$ ConnectionStrings:RTUConnectionString %>" 
            SelectCommand="SELECT *, '' LogInput FROM [nei_list] WHERE [nei_id]=@ID">
                <SelectParameters>
                <asp:QueryStringParameter Name="ID" QueryStringField="ID" />
            </SelectParameters>
        </asp:SqlDataSource>

        <asp:SqlDataSource ID="SqlNEIT" runat="server" ConnectionString="<%$ ConnectionStrings:RTUConnectionString %>" 
            SelectCommand="SELECT ID TID, CLLI, EquipmentType, Officecode, OfficeName, WorkingLines, Testable Tstbl FROM NEI_Testable WHERE CLLI=@ID ORDER BY [EquipmentType], OfficeCode"
            UpdateCommand="UPDATE NEI_Testable SET Testable = @Tstbl WHERE ID=@TID"
            >
            <SelectParameters>
                <asp:QueryStringParameter Name="ID" QueryStringField="ID" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="Tstbl" Type="String" />
                <asp:Parameter Name="TID" Type="String" />

            </UpdateParameters>
        </asp:SqlDataSource>

        <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlSource" DefaultMode="ReadOnly">
            <EditItemTemplate>
                <table cellpadding="6" style="width: 100%">
                    <tr style="font-size:large; background-color: #006600; color: #FFFFFF;">
                        <td style="padding: 2px" align="center"></b></td>
                        <td style="padding: 2px" colspan="5" align="left"><b>NEI Maintenance and Inventory Log</b></td></tr>
                <tr>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>Location ID:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Textbox ID="txtLocID" runat="server" Text='<%# Bind("Location_ID") %>' /></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>Location Name:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Textbox ID="txtLocName" runat="server" Text='<%# Bind("LOCATION_NAME") %>' /></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>NET_LOC_TYPE_ID:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Textbox ID="txtNETLOC" runat="server" Text='<%# Bind("NET_LOC_TYPE_ID") %>' /></td>
                </tr>
                <tr>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>Host:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Textbox ID="txtHOST" runat="server" Text='<%# Bind("MAIN_ID") %>' /></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>EXCH AREA CLLI:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Textbox ID="txtEXCH" runat="server" Text='<%# Bind("EXCHANGE_AREA_CLLI") %>' /></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>OP CO NUM:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Textbox ID="txtOPCO" runat="server" Text='<%# Bind("OPERATING_COMPANY_NUMBER") %>' /></td>
                </tr>
                <tr>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B></B></td>
                    <td style="font-size:small; background-color:#E8E8E8; color: #333333; width: 130px;"><B>System:</B></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>Testable:</B></td>
                    <td style="font-size:small; background-color:#E8E8E8; color: #333333; width: 130px;"><B>RTU:</B></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>EXT:</B></td>
                    <td style="font-size:small; background-color:#E8E8E8; color: #333333; width: 130px;"><B>NEI:</B></td>
                </tr>
                <tr>
                    <td style="font-size:medium; background-color: #CEF6CE;color: #284775; "></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; ">
                        <asp:DropDownList ID="ddlSys" runat="server" SelectedValue='<%# Bind("system") %>' Enabled="True" >
                            <asp:ListItem Value="AC" Selected="True">AC</asp:ListItem>
                            <asp:ListItem Value="OSG" Selected="True">OSG</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td style="font-size:medium; background-color: #CEF6CE;color: #284775; ">
                        <asp:DropDownList ID="ddlTst" runat="server" SelectedValue='<%# Bind("testable") %>' Enabled="True" >
                            <asp:ListItem Value="YES" Selected="True">YES</asp:ListItem>
                            <asp:ListItem Value="NO" Selected="True">NO</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; ">
                        <asp:DropDownList ID="ddlRTU" runat="server" SelectedValue='<%# Bind("RTU") %>' Enabled="True" >
                            <asp:ListItem Value="YES" Selected="True">YES</asp:ListItem>
                            <asp:ListItem Value="NO" Selected="True">NO</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td style="font-size:medium; background-color: #CEF6CE;color: #284775; ">
                        <asp:DropDownList ID="ddlEXT" runat="server" SelectedValue='<%# Bind("EXT") %>' Enabled="True" >
                            <asp:ListItem Value="YES" Selected="True">YES</asp:ListItem>
                            <asp:ListItem Value="NO" Selected="True">NO</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; ">
                        <asp:DropDownList ID="ddlNEI" runat="server" SelectedValue='<%# Bind("NEI") %>' Enabled="True" >
                            <asp:ListItem Value="YES" Selected="True">YES</asp:ListItem>
                            <asp:ListItem Value="NO" Selected="True">NO</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; text-align:center"><B>*<%#Request.Cookies["RTUA"]["NAME"].ToString() %>*<br />*<%#DateTime.Now.ToString("MM-dd-yyyy h:mmtt") %>*</B></td>
                    <td colspan="5" style="font-size:medium; background-color: #E8E8E8;color: #284775;"><asp:Textbox ID="txtREMARKS" runat="server" Text='<%# Bind("LogInput") %>'  Rows="5" TextMode="MultiLine" Width="100%" /></td>
                </tr>
                    <tr style="font-size:large; background-color: #006600; color: #FFFFFF;">
                        <td style="padding: 2px" align="center"><b><asp:button id="UpdateButton"  CausesValidation="True" text="Update" commandname="Update" runat="server" ForeColor="#003300"/> </b></td>
                        <td style="padding: 2px" colspan="5" align="left"><b></b></td></tr>
                <tr>
                </tr>
                </table>
            </EditItemTemplate>
            <ItemTemplate>
                <table cellpadding="6" style="width: 100%">
                    <tr style="font-size:large; background-color: #006600; color: #FFFFFF;">
                        <td style="padding: 2px" align="center"><b><asp:button id="EditButton" text="EDIT" commandname="Edit" runat="server" ForeColor="#003300"/> </b></td>
                        <td style="padding: 2px" colspan="5" align="left"><b>NEI Maintenance and Inventory Log</b></td></tr>
                <tr>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>Location ID:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Label ID="lblLocID" runat="server" Text='<%# Bind("Location_ID") %>' /></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>Location Name:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Label ID="lblLocName" runat="server" Text='<%# Bind("LOCATION_NAME") %>' /></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>NET_LOC_TYPE_ID:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Textbox ID="lblNETLOC" runat="server" Text='<%# Bind("NET_LOC_TYPE_ID") %>' /></td>
                </tr>
                <tr>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>Host:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Label ID="lblHOST" runat="server" Text='<%# Bind("MAIN_ID") %>' /></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>EXCH AREA CLLI:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Label ID="lblEXCH" runat="server" Text='<%# Bind("EXCHANGE_AREA_CLLI") %>' /></td>
                    <td style="font-size:small; background-color:#CEF6CE; color: #333333; width: 130px;"><B>OP CO NUM:</B></td>
                    <td style="font-size:medium; background-color: #E8E8E8;color: #284775; "><asp:Label ID="lblOPCO" runat="server" Text='<%# Bind("OPERATING_COMPANY_NUMBER") %>' /></td>
                </tr>
                </Table>
            </ItemTemplate>

        </asp:FormView>


                    <asp:ListView ID="lvNEIT" runat="server" DataSourceID="SqlNEIT">                       
                    <ItemTemplate>
                            <tr style="font-size:small; background-color: #FFFFFF;color: #284775;">
                            <td></td>
                            <td align="center">
                                <asp:Label ID="lblNEIID" runat="server" Text='<%# Bind("TID") %>' Visible="false" />
                                <asp:Label ID="lblNEIEQT" runat="server" Text='<%# Eval("EquipmentType") %>' />
                            </td>
                            <td align="center">
                                <asp:Label ID="lblNEION" runat="server" Text='<%# Eval("OfficeName") %>' />
                            </td>
                            <td align="center">
                                <asp:Label ID="lblNEIOC" runat="server" Text='<%# Eval("OfficeCode") %>' />
                            </td>
                            <td align="center">
                                <asp:Label ID="lblNEIWL" runat="server" Text='<%# Eval("WorkingLines") %>' />
                            </td>
                            <td align="right">
                                <asp:DropDownList ID="ddlNEITST" runat="server" SelectedValue='<%# Bind("Tstbl") %>' Enabled="False" >
                                    <asp:ListItem Value="YES" Selected="True">YES</asp:ListItem>
                                    <asp:ListItem Value="NO" Selected="True">NO</asp:ListItem>
                                    <asp:ListItem Value="UNK" Selected="True">UNK</asp:ListItem>
                                </asp:DropDownList>
                                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                                <asp:LinkButton ID="btnNEIEdit" runat="server" Text="Edit" CommandName="Edit" />
                            </td>
                        </tr>
                    </ItemTemplate>
                    <EditItemTemplate>                                
                        <tr style="font-size:small; background-color: #FFFFFF;color: #284775;">
                            <td></td>
                            <td align="center">
                                <asp:Label ID="lblNEIID" runat="server" Text='<%# Bind("TID") %>' Visible="false" />
                                <asp:Label ID="lblNEIEQT" runat="server" Text='<%# Bind("EquipmentType") %>' />
                            </td>
                            <td align="center">
                                <asp:Label ID="lblNEION" runat="server" Text='<%# Bind("OfficeName") %>' />
                            </td>
                            <td align="center">
                                <asp:Label ID="lblNEIOC" runat="server" Text='<%# Bind("OfficeCode") %>' />
                            </td>
                            <td align="center">
                                <asp:Label ID="lblNEIWL" runat="server" Text='<%# Bind("WorkingLines") %>' />
                            </td>
                            <td align="right">
                                <asp:DropDownList ID="ddlNEITST" runat="server" SelectedValue='<%# Bind("Tstbl") %>' Enabled="True" >
                                    <asp:ListItem Value="YES" Selected="True">YES</asp:ListItem>
                                    <asp:ListItem Value="NO" Selected="True">NO</asp:ListItem>
                                    <asp:ListItem Value="UNK" Selected="True">UNK</asp:ListItem>
                                </asp:DropDownList>
                                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
                                <asp:LinkButton ID="btnNEISave" runat="server" Text="Update" CommandName="Update" />
                            </td>
                        </tr>

                    </EditItemTemplate>
                    <LayoutTemplate>
                        <table width="98%" cellpadding="5" cellspacing="3" runat="server">
                            <tr align="center" runat="server">
                                <td runat="server">
                                        <table id="itemPlaceholderContainer" runat="server" border="1" style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">

                        <tr></tr>
                            <tr runat="server" style="font-size:small; background-color:#006600; color: #FFFFFF;">
                                <th runat="server"></th>
                                <th runat="server">EquipmentType</th>
                                <th runat="server">OfficeName</th>
                                <th runat="server">OfficeCode</th>
                                <th runat="server">WorkingLines</th>
                                <th runat="server">Testable</th>
                            </tr>
                            <tr id="itemPlaceholder" runat="server">
                            </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </LayoutTemplate>
                    </asp:ListView>

提前感谢

您应该使用ListBox控件而不是dropdownlist

       <asp:ListBox runat="server" ID="ddlSys" SelectionMode="multiple">
       <asp:ListItem Value="AC" Selected="True">AC</asp:ListItem>
        <asp:ListItem Value="OSG" Selected="True">OSG</asp:ListItem>
       </asp:ListBox> 

我的ListItem中包含的每一个Selected=True。去掉这个,一切都很完美


似乎这个愚蠢的错误会导致页面在第一次绑定事件时失败,而不仅仅是在FormView和ListView都处于编辑模式时发生。

为什么是ListBox?它应该是一个非此即彼的选项,所以SelectionMode=multiple是错误的。此外,您选择交换的ddlSys位于FormView中,它本身就可以正常工作。导致错误的是ListView组件。这个选择也应该是一个非此即彼的选项。好的,我明白了。这些应该一直是一项选择,由SelectedValue=设置。谢谢你引起我的注意。