首先,在dropdownlist显示的时候,有些selectedvalue是空值,这个时候如果不处理的话,就会提示
类似“数组越界之类的”,这个时候可以采用下列方式解决(参考http://hrj0130.blog.163.com/blog/static/24305432009228101931652/)
1、静态声明
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="ObjectDataSource1" DataTextField="Name" DataValueField="ID" SelectedValue='<%# Bind("ParentID") %>' Style="position: relative" AppendDataBoundItems="True"> <asp:ListItem Value="">(无 或 空 或 all)</asp:ListItem><!--需要增加的内容--> </asp:DropDownList>
可以在指定datasource之后,在添加心得item,但是要注意加上
AppendDataBoundItems="True"
2、动态编程
ListItem newItem = new ListItem("请选择文章作者","");//新建item this.AUTHOR_ID.Items.Add(newItem);//添加
其次,获得返回值用的是selectedValue
int schoolId = Int16.Parse(((DropDownList)row.Cells[6].FindControl("school")).SelectedValue);