好像要加上
DropDownList1.DataTextField="字段名";DropDownList1.DataValueField="字段名";
DropDownList1.DataTextField="字段名";DropDownList1.DataValueField="字段名";
解决方案 »
- Asp.net调用 xxx.dll在vs2005上调试正常,发布到IIS7.0调试时出错。应用程序池关闭
- 页面传递参数的问题
- 新闻正则高手来
- ViewState会超时吗
- VS.NET开发页面下连接本机数据库服务连不上
- 菜鸟问题,如何对access批量插入有规律的数据
- VS2008启动调试失败,请高手指点!
- 十万火急!byte[] ascii={}中,{}里只能放具体的数字么? 可部可以放变量???
- 为什么我按saucer(思归/MVP 提供的地址的方法 做的上传程序 产生的图片,查看的时候显示是*呢,我是一点都没变
- 一个按钮的功能,需要长期大量占用CPU,如何缓解功能执行期间的CPU占用率呢?
- 为什么Session_End和Application_End都不能执行 (在线等)
- ASP.NET的网络办公
楼上正解
this.DropDownList1.DataSource=this.allusername;DropDownList1.DataTextField="字段名";DropDownList1.DataValueField="字段名";
this.DropDownList1.DataBind();
{
Conn.Open();
Cmd =new OleDbCommand(strsql,Conn);
OleDbDataReader Rd = Cmd.ExecuteReader();
list.DataSource=Rd;
list.DataTextField=TextField;//你的DDl内的item显示的内容
list.DataValueField=ValueField;//你的ddl的item生成的html<option value=...中value的值
list.DataBind();
list.SelectedIndex = 0;
Rd.Close();
Conn.Close();
}}
//allusername 是datareader,返回一个表的记录
this.DropDownList1.DataSource=this.allusername;
DropDownList1.DataTextField="MemberName"; DropDownList1.DataValueField="MemberName";
this.DropDownList1.DataBind();
绑定完了以后,下拉出来所有的用户名,但是无论我选哪个用户名,他的值都是下拉选项中第一个用户名的值,晕,而且selectindex 永远都是0,还有,DropDownList1_SelectedIndexChanged事件在我选择的时候也不触发,这是怎么回事呀,大哥
cn.Open();
string cmStr="select * from researchtab where tablename='"+tablename+"'" ;
SqlCommand cm=new SqlCommand (cmStr,cn);
SqlDataReader dr=cm.ExecuteReader();
while (dr.Read())
{
DropDownList1.Items.Add(new ListItem(dr["chinesename"].ToString(),dr["FieldName"].ToString()));
LX.Items.Add(new ListItem(dr["ReferTab"].ToString(),dr["Kind"].ToString()));
}
if(!IsPostBack)
{
//绑定程序
......}
if(!IsPostBack)
{
BindDp();}
public void BindDp()
{
//绑定程序}