假设你的部门表为dep,以下程序即可:
private void Page_Load(Object Src, EventArgs E) {
SqlConnection mycon=new SqlConnection("server=yourserver;uid=sa;
pwd=;database=databsae");
SqlDataAdapter myad=new SqlDataAdapter("select Dep_id,Dep_name from dep",mycon);
DataSet mds=new DataSet();
myad.Fill(mds,"dep");
ListBox1.DataSource=mds.Tables["dep"].DefaultView;
ListBox1.DataTextField=mds.Tables["dep"].Columns["Dep_name"].ToString();
ListBox1.DataValueField=mds.Tables["dep"].Columns["Dep_id"].ToString();
ListBox1.DataBind();
}部门:<asp:DropDownList id="ListBox1" runat="server"/>
private void Page_Load(Object Src, EventArgs E) {
SqlConnection mycon=new SqlConnection("server=yourserver;uid=sa;
pwd=;database=databsae");
SqlDataAdapter myad=new SqlDataAdapter("select Dep_id,Dep_name from dep",mycon);
DataSet mds=new DataSet();
myad.Fill(mds,"dep");
ListBox1.DataSource=mds.Tables["dep"].DefaultView;
ListBox1.DataTextField=mds.Tables["dep"].Columns["Dep_name"].ToString();
ListBox1.DataValueField=mds.Tables["dep"].Columns["Dep_id"].ToString();
ListBox1.DataBind();
}部门:<asp:DropDownList id="ListBox1" runat="server"/>
解决方案 »
- 求助!!!Datalist 高亮问题【40分】
- 请问有人知道asp.net中加入ascx控件后Button无事件了,是怎么回事?
- 怎样在ASP页面中添加搜索引擎?
- .NET怎样实现文件的下载?????
- 通信录怎么设计比较好?
- 如何根据分辨率的不同,动态的调整table的显示高度呢??(大虾帮忙)
- textbox在Page_Load赋值之后update不能修改的问题。帮帮忙.
- 如何实现DATAGRID里按钮列的一个经典问题?????
- 类似CORELDRAW中图像的卷页效果如何在C#中实现?
- 如果用正则表达式来检索文本中的某些字段
- datalist删除问题
- 关于Windows .NET 使用ASP .NET
SqlConnection mycon=new SqlConnection("Server;uid=;pwd=;database=");
SqlDataAdapter myad1=new SqlDataAdapter("select groupid,groupname from SysGroups order by groupid asc",mycon);
DataSet mds=new DataSet();
myad1.Fill(mds,"Sysgroups");
DropDownList1.DataSource=mds.Tables["Sysgroups"].DefaultView;
DropDownList1.DataTextField=mds.Tables["Sysgroups"].Columns["groupname"].ToString();
DropDownList1.DataValueField=mds.Tables["Sysgroups"].Columns["groupid"].ToString();
DropDownList1.DataBind();
mycon.Close();
<ItemTemplate>
<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="False" />
</ItemTemplate>
</asp:TemplateColumn>