我写了一个gridview嵌套DropDownList 这个DropDownList,但发现有些记录不在1,2,3选项里,造成出现"DropDownList1”有一个无效 SelectedValue,因为它不在项目列表中的错误",所以我想能不能在codeBehind里动态判断一下是否有效,无效再让SelectedValue="请选择",请高人指点,谢谢!代码如下:<asp:GridView ID="GridView1" ...>
<asp:TemplateField HeaderText="所属类别">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataField="songtype" SelectedValue =<%# Bind("songtype")%>
AutoPostBack="true" >
<asp:ListItem Value="1">流行翻唱</asp:ListItem>
<asp:ListItem Value="2" >独奏古典</asp:ListItem>
<asp:ListItem Value="3">原创弹唱</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
... .... </asp:GridView>
<asp:TemplateField HeaderText="所属类别">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataField="songtype" SelectedValue =<%# Bind("songtype")%>
AutoPostBack="true" >
<asp:ListItem Value="1">流行翻唱</asp:ListItem>
<asp:ListItem Value="2" >独奏古典</asp:ListItem>
<asp:ListItem Value="3">原创弹唱</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
... .... </asp:GridView>
DropDownList1.Items.Insert(0, new ListItem("-请选择-", "0"));DropDownList1.Items.Insert(0, new ListItem("-请选择-", "4"));DropDownList1.Items.Insert(0, new ListItem("-请选择-", "5"));
public string aa(object obj)
{
//logic....
return ...
}