dropdownlist联动效果

来源:百度知道 编辑:UC知道 时间:2024/05/21 22:50:39
就像做注册信息时选择地址时
dropdownlist控件
湖北 武汉 武昌 这样用泛型list<>
该怎样做了
最好能有具体的代码
谢谢
我先不管它刷不刷新哈
只要能达到选就出结果的效果出来就行了哈

不能那添加哈
现在光键要用泛型向里面加数据
但是我对泛型不是很懂
所以就……

list<> 代表一个键和值的成对,

建议你多看看泛型类, MSDN上面有。

示例如下:
protected void Button1_Click(object sender, EventArgs e)
{
DropDownList1.DataTextField = "value";
DropDownList1.DataValueField = "key";
DropDownList1.DataSource = getTypeList();
DropDownList1.DataBind();
}
public Dictionary<int, string> getTypeList()//泛型类;
{
Dictionary<int, string> list = new Dictionary<int, string>();
list.Add(1, "湖南");
list.Add(2, "湖北");
list.Add(3, "上海");
list.Add(4, "北京");
return list;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write(DropDownList1.SelectedValue.ToString());
}

启用autoPostBack=true 在Change事件中改变下级列表的数据

首先,把注册信息的地址字段转化成模板,再选择编辑模板,
在 地址 模板的EditItem Template 下,拖进一个DropDownList,
假如不从数据库导入信息的话,可以直接在Item属性里添加,应该就可以了。。<