询问一下,DropDownList1能否同时绑定一个表中两列的值
解决方案 »
- .NET Web调试的时候出现严重的问题,求高手解决
- 关于企业招聘要求的疑惑
- 请问 关于 asp.net ajax 问题
- 求正则表达式:替换掉字符串中所有“=”号前后的空格
- repeater中的删除前怎样添加个确认删除对话框?你确认要删除吗?
- 注销功能问题用session.clear(),请大家帮忙
- TreePanel+TabPanel加载内容页面问题
- DataGrid里点一行(点行的任何地方),取出这行的数据~大家帮帮我
- firefox如何得到上传的路径啊
- Visual Studio.NET 已检测到指定的Web服务器运行的不是ASP.NET1.1版.你将无法运行ASP.NET Web应用程序或服务.(在线等待!!)
- 为什么asp.net中Timer控件不执行Tick事件
- 菜鸟再问关于SQL SERVER2000数据库中存取图片的问题
Text一列
Value一列
我希望在DropDownList1的下拉框中显示name+id
System.Data.SqlClient.SqlConnection sqlconn = new System.Data.SqlClient.SqlConnection();
sqlconn.ConnectionString ="user id=sa;password=;initial catalog=System_manage;Server=.";
sqlconn.Open();
//System.Data.SqlClient.SqlDataAdapter sqldar = new System.Data.SqlClient.SqlDataAdapter("select table1.id,table2.name from LoginTable table1 join LoginTable table2 on table1.phone=table2.phone",sqlconn);
System.Data.SqlClient.SqlDataAdapter sqldar = new System.Data.SqlClient.SqlDataAdapter("select id,name from LoginTable",sqlconn);
sqldar.SelectCommand.CommandType = CommandType.Text;
System.Data.DataSet DataSet1= new System.Data.DataSet();
sqldar.Fill(DataSet1,"Users");
DropDownList1.DataSource = DataSet1.Tables["Users"].Columns.ToString();
DropDownList1.DataTextField="id";
DropDownList1.DataTextField="name";
DropDownList1.DataValueField="name";
DropDownList1.DataBind();
Response.Write("绑定成功");
sqlconn.Close();
下面是部分代码,希望各位看一下
System.Data.SqlClient.SqlConnection sqlconn = new System.Data.SqlClient.SqlConnection();
sqlconn.ConnectionString ="user id=sa;password=;initial catalog=System_manage;Server=.";
sqlconn.Open();
System.Data.SqlClient.SqlDataAdapter sqldar = new System.Data.SqlClient.SqlDataAdapter("select cast(id as varchar(10)) + a1 as name1 from ac",sqlconn);
sqldar.SelectCommand.CommandType = CommandType.Text;
System.Data.DataSet DataSet1= new System.Data.DataSet();
sqldar.Fill(DataSet1,"Users");
DropDownList1.DataSource = DataSet1.Tables["Users"].DefaultView;
DropDownList1.DataTextField="name";
DropDownList1.DataValueField="name"
DropDownList1.DataBind();
sqlconn.Close()