在gridview中绑定Dropdownlist,遇到过如下错误吗?

“DropDownList2”有一个无效 SelectedValue,因为它不在项目列表中。

参数名: value

解决办法:

 <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="LinqDataSource1"
                                            DataTextField="GroupName" DataValueField="itemid" SelectedValue='<%#Bind("Groupname")%>' AppendDataBoundItems=true>
                                            <asp:ListItem Value="">无分组</asp:ListItem>

                                        </asp:DropDownList>

问题关键:AppendDataBoundItems=true和默认值<asp:ListItem Value="">无分组</asp:ListItem>


                                            DataTextField
="GroupName" DataValueField="itemid" SelectedValue='<%#Bind("Groupname")%>' AppendDataBoundItems=true>
                                            
<asp:ListItem Value="">无分组</asp:ListItem>

                                        </asp:DropDownList>

问题关键就是AppendDataBoundItems=true这个属性,还有加<asp:ListItem Value="">无分组</asp:ListItem>默认值。

 


                                            DataTextField
="GroupName" DataValueField="itemid" SelectedValue='<%#Bind("Groupname")%>'>
                                            
<asp:ListItem Value="">无分组</asp:ListItem>
                                        
</asp:DropDownList

 

 

 

相关文章:

  • 2022-12-23
  • 2021-07-29
  • 2021-12-13
  • 2022-03-03
  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2021-08-14
  • 2022-02-16
相关资源
相似解决方案