下拉列表的可以分为两种 一种写死在html里面 功能类似与一个选择按钮,用作类型选择
<f:DropDownList runat="server" ID="developLvlDropDownList" Label ="发达程度" AutoPostBack="true" >
<f:ListItem Text="请选择发达程度" Value="-1" Selected="true" EnableSelect="false"/>
<f:ListItem Text="贫穷" Value="1" />
<f:ListItem Text="一般" Value="2"/>
<f:ListItem Text="发达" Value="3"/>
</f:DropDownList>
另一种形式是动态的生成数据 根据外部的数据形成下拉菜单的内容,例如我们见到的多层级下拉菜单
在html中
<f:DropDownList runat="server" OnSelectedIndexChanged="dropListSelectedIndexChange" AutoPostBack="true" EnableEdit="false" LabelAlign="Top" ID="DropDownList1" Label="一级单位:" Hidden="false">
</f:DropDownList>
这时需要使用到的参数信息
AutoPostBack="true" // 接受回发请求
OnSelectedIndexChanged="" //当选中下标变化时触发
绑定数据源
DataTable cityTable = new DataTable(); DataColumn column1 = new DataColumn("text", typeof(string)); DataColumn column2 = new DataColumn("value", typeof(string)); cityTable.Columns.Add(column1); cityTable.Columns.Add(column2); DataRow row = cityTable.NewRow(); row[0] = "beijing";
row[1] = "1";
countyDropDownList.SelectedValue = "-1";countyDropDownList.DataTextField = "text"; countyDropDownList.DataValueField = "value"; countyDropDownList.DataSource = cityTable; countyDropDownList.DataBind(); countyDropDownList.Items.Insert(0, new FineUI.ListItem("选择市区", "-1")); countyDropDownList.SelectedValue = "-1";
顺便说一下层级下拉菜单的思路,2个比较重要的点:
1是获取数据的上级参数
2是当前选中值
如果是初始化 上级参数是原始数据中上级的值 选中值是原始数据值
如果非初始化 上级数据是上级控件当前选种值 选中值为-1