如何从数据库asp.net填充的DropDownList? [英] how to fill DropDownList from database in asp.net?

查看:88
本文介绍了如何从数据库asp.net填充的DropDownList?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从数据库asp.net填充的DropDownList?

how to fill DropDownList from database in asp.net ?

而当我拿起从DropDownList的价值如何抓住这个活动?

and when i pick value from the DropDownList how to catch this event ?

Conn.Open();
SQL = "SELECT distinct city FROM MEN";
dsView = new DataSet();
adp = new SqlDataAdapter(SQL, Conn);
adp.Fill(dsView, "MEN");
adp.Dispose();

DropDownList1. ?????? (what do to ?)

在此先感谢

推荐答案

您设定的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedataboundcontrol.datasource.aspx\"相对=nofollow> 数据源 ,<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.datatextfield.aspx\"相对=nofollow> DataTextField 和<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.datavaluefield.aspx\"相对=nofollow> DataValueField 和呼叫的 的DataBind() 以填充DropDownList的。

You set the DataSource, DataTextField and DataValueField and call DataBind() in order to populate the dropdownlist.

数据源可以是pretty多的的IEnumerable 以及文本和值将被查找与反思。

The datasource can be pretty much any IEnumerable and the text and value will be looked up with reflection.

你想赶上这次活动是<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedindexchanged.aspx\"相对=nofollow> 的SelectedIndexChanged 事件 - 当你改变选择,这将触发

The event you want to catch is the SelectedIndexChanged event - this will fire when you change the selection.

这篇关于如何从数据库asp.net填充的DropDownList?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆