问题:
我的界面上有两DropDownList控件,它们的数据源是一样的,都是来自于同一个SqlDataReader,但为什么只有其中一个有数据,另一个没有? 如下代码:SqlConnection myConnection = new SqlConnection(...);
String cmdText ="SELECT ....";
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
myConnection.Open();
SqlDataReader recm = myCommand.ExecuteReader();
DropDownList1.DataSource = recm;
DropDownList1.DataTextField = "EmployeName";
DropDownList1.DataValueField="EmployeId";
DropDownList1.DataBind();
DropDownList2.DataSource = recm;
DropDownList2.DataTextField = "EmployeName";
DropDownList2.DataValueField="EmployeId";
DropDownList2.DataBind();我知道这种情况用SqlDataReader可能不合适,但我不知该用什么,大家有更好的建议吗?能不能写完整点的代码,因为我很菜的.
我的界面上有两DropDownList控件,它们的数据源是一样的,都是来自于同一个SqlDataReader,但为什么只有其中一个有数据,另一个没有? 如下代码:SqlConnection myConnection = new SqlConnection(...);
String cmdText ="SELECT ....";
SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
myConnection.Open();
SqlDataReader recm = myCommand.ExecuteReader();
DropDownList1.DataSource = recm;
DropDownList1.DataTextField = "EmployeName";
DropDownList1.DataValueField="EmployeId";
DropDownList1.DataBind();
DropDownList2.DataSource = recm;
DropDownList2.DataTextField = "EmployeName";
DropDownList2.DataValueField="EmployeId";
DropDownList2.DataBind();我知道这种情况用SqlDataReader可能不合适,但我不知该用什么,大家有更好的建议吗?能不能写完整点的代码,因为我很菜的.
解决方案 »
- asp.net 同时多个表插入数据
- mvc如何在前台循环显示的时候 绑定一个control的方法,显示出不同的值。像以前调用后台prodected方法那样?
- asp<img>控件显示图片
- 问问程序员和美工如何配合的办法
- ASP.NET发布后局部更新
- 请教一个脚本错误的问题!
- 各位朋友,请问谁有网页维护界面的CSS样例
- 怎样把一个table的四个角做成平滑的曲线?
- 有关Page_Err和HttpRequestValidationException的问题,期待高手指点。
- 关于2000pro下安装Studio .Net的问题,郁闷中...
- 菜鸟请各位大侠帮忙!!!! 在线等
- 在做.Net2的时候TreeView 控件怎么才可以有滚动条啊?
DataSet ds=GetDataSet(cmdText);DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "EmployeName";
DropDownList1.DataValueField="EmployeId";
DropDownList1.DataBind();
DropDownList2.DataSource = ds;DropDownList2.DataTextField = "EmployeName";
DropDownList2.DataValueField="EmployeId";
DropDownList2.DataBind();//
public static DataSet GetDataSet(string sql)
{
string ConnectionString="连接字符串";
SqlDataAdapter sda =new SqlDataAdapter(sql,ConnectionString);
DataSet ds=new DataSet();
sda.Fill(ds);
return ds;
}
String cmdText = "SELECT DISTINCT RoomID FROM Room WHERE RoomBedMan is NULL OR RoomBedMan = 0 ORDER BY RoomID";
myConnection.Open();
SqlDataAdapter sdaRoom = new SqlDataAdapter(cmdText,myConnection);
DataSet dsRoom = new DataSet();
sdaRoom.Fill(dsRoom);
addBedRoomID.DataSource = dsRoom;
addBedRoomID.DataValueField = "RoomID";
addBedRoomID.DataTextField = "RoomID";
addBedRoomID.DataBind();
ddlVacantRoom.DataSource = dsRoom;
ddlVacantRoom.DataValueField = "RoomID";
ddlVacantRoom.DataTextField = "RoomID";
ddlVacantRoom.DataBind();
}