在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
<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