dropdown.DataSource = dt //dt是DataTable
dropdown.DataTextField = "column1" //column1是dt的列名
dropdown.DataValueField = "column2" //column2是dt的列名
dropdown.DataBind()dim strValue as string
strValue = this.dropdown.SelectedItem.Value.ToString()//取到DropDownList中选中项的Value值
dropdown.DataTextField = "column1" //column1是dt的列名
dropdown.DataValueField = "column2" //column2是dt的列名
dropdown.DataBind()dim strValue as string
strValue = this.dropdown.SelectedItem.Value.ToString()//取到DropDownList中选中项的Value值
解决方案 »
- asp.net xml 添加数据 (在线等) 出答案立刻结贴
- 一个方法的求助
- 我就想查询数据库 然后进行显示 请教
- datalist中获取值的方法
- 灵异事件?
- EXCEL读取数据问题
- Context.Request.Url.Authority取出来怎么总是"localhost",那位指点一下,是不是有什么设置
- 在制作安装程序的时候,怎么将水晶报表的相关库打包进去阿???
- 请问各位高手那里有树型控件的下栽?
- 怎么链接到子目录中去?比如当前是http://192.168.0.11/aaa,然后转到http://192.168.0.11/aaa/bbb
- DataGrid效率问题,欢迎大家讨论?
- 能不能定义一个整个网站都能用的全局变量,在哪里定义,怎么用?谢谢!
myDrop.DataSource = dataTable; //dataTable是已经有数据的DataTable
myDrop.DataTextField = "TextField";
myDrop.DataValueField = "ValueField";
myDrop.DataBind(); //绑定
myDrop.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged); //注册事件//你的事件处理过程
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
string strconn = ConfigurationSettings.AppSettings["contodata"];
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string sqlstr = "select xm from xsxx";
SqlCommand cmd = new SqlCommand(sqlstr,conn);
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "xm";
DropDownList1.DataBind();
conn.Close();
//注册事件
DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged); 需要注意的是你的页面每次提交的时候都要加载创建这一过程