報錯:DropDownList1”有一個無效 SelectedValue,因爲它不在項目列表中

錯誤:

“DropDownList1”有一個無效 SelectedValue,因爲它不在項目列表中。

參數名: value

解決辦法:

在下拉框里加一個:<asp:ListItem Value=""> </asp:ListItem>

例如:編輯下拉框時

<asp:TemplateColumn HeaderText="評定等級">
                    <ItemTemplate>
                        <asp:Label ID="Label7" runat="server" Text='<%#Eval("評定等級") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList1" runat="server" CssClass="select_n_100" Text='<%#Eval("評定等級") %>'>
                            <asp:ListItem value=""></asp:ListItem>
                            <asp:ListItem Value="紅" Text="紅"></asp:ListItem>
                            <asp:ListItem Value="橙" Text="橙"></asp:ListItem>
                            <asp:ListItem Value="黃" Text="黃"></asp:ListItem>
                            <asp:ListItem Value="藍" Text="藍"></asp:ListItem>
                        </asp:DropDownList>
                        <asp:Label ID="Label6" runat="server" Text='<%#Eval("評定等級") %>'></asp:Label>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="DropDownList2" runat="server" CssClass="select_n_100">
                            <asp:ListItem Value="1">紅</asp:ListItem>
                            <asp:ListItem Value="2">橙</asp:ListItem>
                            <asp:ListItem Value="3">黃</asp:ListItem>
                            <asp:ListItem Value="4">藍</asp:ListItem>
                        </asp:DropDownList>
                         <asp:Label ID="Label8" runat="server" Text='<%#Eval("評定等級") %>'></asp:Label>
                    </FooterTemplate>
</asp:TemplateColumn>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章