填充数据库中的下拉项 [英] Filling the dropdown item from the database

查看:62
本文介绍了填充数据库中的下拉项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何填充db中的combobx下拉列表

How do i fill the dropdown of combobx from a db

推荐答案

从数据库中获取结果
Get the result from database
//clsUser is my own defined class with the UserSelect method
clsUser objUsers = new clsUser();
DataTable dtUser = objUsers.UserSelect("Select * from Users");

//take a combobox in front end or in codebehind
ComboBox cmb = new ComboBox();
cmb.DropDownStyle = ComboBoxStyle.DropDownList;
//set the datasource 
cmb.DataSource = dtUser.Copy();


您应该至少在Google上搜索从数据库C#填充组合框".甚至还有一个youtube视频显示了如何执行此操作:
http://www.youtube.com/watch?v=izlgxu51RoQ [ http://www.dreamincode.net/forums/topic /145973-fill-data-from-database-in-the-combobox/ [ http://forums.codeguru.com/showthread.php?472847- Populate-ComboBox-from-db-Select-RecordID [ ^ ]
You should have at least googled for "fill combobox from database c#". There is even a youtube video showing how to do that:
http://www.youtube.com/watch?v=izlgxu51RoQ[^]
or read these forum posts:
http://www.dreamincode.net/forums/topic/145973-fill-data-from-database-in-the-combobox/[^]
http://forums.codeguru.com/showthread.php?472847-Populate-ComboBox-from-db-Select-RecordID[^]


尝试一下,

Try this,

DropDownList1.DataSource = dt;
       DropDownList1.DataTextField = "Name";
       DropDownList1.DataValueField = "ID";
       DropDownList1.DataBind();


这篇关于填充数据库中的下拉项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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