CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

为什么DropDownList绑定不上数据?高手们看看!

楼主psgogogo()2005-04-01 00:55:10 在 .NET技术 / ASP.NET 提问

---------*.CS----------------  
   
  using   System;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Data;  
  using   System.Drawing;  
  using   System.Web;  
  using   System.Web.SessionState;  
  using   System.Web.UI;  
  using   System.Web.UI.WebControls;  
  using   System.Web.UI.HtmlControls;  
   
  namespace   biz2  
  {  
  ///   <summary>  
  ///   AddSite   的摘要说明。  
  ///   </summary>  
  public   class   AddSite   :   System.Web.UI.Page  
  {  
  protected   System.Web.UI.WebControls.TextBox   sname;  
  protected   System.Web.UI.WebControls.TextBox   sUrl;  
  public   System.Web.UI.WebControls.DropDownList   sType;  
  protected   System.Web.UI.WebControls.TextBox   s;  
  protected   System.Web.UI.HtmlControls.HtmlGenericControl   P1;  
  Pub   pub=new   Pub();  
   
  public   void   Page_Load(object   sender,   System.EventArgs   e)  
  {  
  if   (!Page.IsPostBack)  
  {  
  pub.OpenDb();  
  pub.DDL_List(sType);  
  pub.CloseDb();  
  }  
  }  
   
  #region   Web   窗体设计器生成的代码  
  override   protected   void   OnInit(EventArgs   e)  
  {  
  //  
  //   CODEGEN:   该调用是   ASP.NET   Web   窗体设计器所必需的。  
  //  
  InitializeComponent();  
  base.OnInit(e);  
  }  
   
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {          
  this.sType.SelectedIndexChanged   +=   new   System.EventHandler(this.sType_SelectedIndexChanged);  
  this.Load   +=   new   System.EventHandler(this.Page_Load);  
   
  }  
  #endregion  
   
  private   void   sType_SelectedIndexChanged(object   sender,   System.EventArgs   e)  
  {  
   
  }  
  }  
  }  
   
   
  --------------Pub.CS---------------------  
  using   System;  
  using   System.Collections;  
  using   System.Configuration;  
  using   System.ComponentModel;  
  using   System.Data;  
  using   System.Drawing;  
  using   System.Data.OleDb;  
  using   System.Data.SqlClient;  
  using   System.IO;  
  using   System.Text.RegularExpressions;  
  using   System.Web;  
  using   System.Web.SessionState;  
  using   System.Web.UI;  
  using   System.Web.UI.WebControls;  
  using   System.Web.UI.HtmlControls;  
  using   System.Xml;  
  using   System.Text;  
  using   System.Net;  
  using   System.Net.Sockets;  
   
  namespace   biz2  
  {  
  ///   <summary>  
  ///   Pub   的摘要说明。  
  ///   </summary>  
  public   class   Pub   :   System.Web.UI.Page  
  {  
  OleDbConnection   conn;  
   
  public   Pub()  
  {  
  //  
  //   TODO:   在此处添加构造函数逻辑  
  //  
  }  
  //--------------数据库操作方法---------------------------------------------------------//  
   
  public   void   OpenDb()  
  {  
  string   connstr="Provider=MicroSoft.Jet.OleDb.4.0;   Data   Source="+Server.MapPath(ConfigurationSettings.AppSettings["db_name"]);  
  conn=   new   OleDbConnection(connstr);  
  conn.Open();  
   
  }  
   
  public   void   CloseDb()  
  {  
  conn.Close();  
  }  
   
   
   
  public   void   DDL_List(DropDownList   ddl1)  
  {  
   
  string   sqlstr="select   *   from   wl_type";  
  OleDbCommand   comm=new   OleDbCommand(sqlstr,conn);  
  ddl1.DataSource=comm.ExecuteReader();  
  ddl1.DataTextField="tname";  
  ddl1.DataValueField="tid";  
  ddl1.DataBind();  
  }  
  //---------------------------------------------------------------------------------------//  
   
   
  }  
  }  
  问题点数:0、回复次数:9Top

1 楼saucer(思归)回复于 2005-04-01 01:32:20 得分 0

错误是?  
   
   
  Server.MapPath  
  ==>HttpContext.Current.Server.MapPath  
   
  string   connstr="Provider=MicroSoft.Jet.OleDb.4.0;   Data   Source="+HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["db_name"]);  
  conn=   new   OleDbConnection(connstr);  
  conn.Open();  
  Top

2 楼dzvsyt(一笑天)回复于 2005-04-01 08:23:22 得分 0

没有打开数据库连接吧Top

3 楼chenyu112(晨雨)回复于 2005-04-01 09:14:35 得分 0

取一下选择出的行数Top

4 楼sukaru(逍遥子)回复于 2005-04-01 09:31:32 得分 0

设置一个断点跟踪一下       程序好象没错。Top

5 楼psgogogo()回复于 2005-04-01 09:42:36 得分 0

问题搞定了,谢谢大家,谢谢思归!  
  Top

6 楼psgogogo()回复于 2005-04-01 09:42:55 得分 0

问题搞定了,谢谢大家,谢谢思归!  
  Top

7 楼vzxq(灵感人)回复于 2005-04-01 10:25:14 得分 0

upTop

8 楼nnh(菲一打)回复于 2005-04-01 10:39:28 得分 0

Good.Top

9 楼qqqqin(初涉江湖)回复于 2005-04-04 09:16:17 得分 0

思归老大出马,没什么解决不了的事啊.哈哈.  
  还不给分?Top

相关问题

  • dropdownlist数据绑定问题
  • DropDownlist数据绑定问题?
  • DropDownList数据绑定问题
  • 如何绑定DropDownList的数据?????
  • TemplateColumn的dropdownlist如何绑定数据库?
  • DropDownList绑定数据的问题
  • 问个DropDownLIst数据绑定问题!!!
  • 如何将DropDownList绑定到数据源?
  • DropDownList数据绑定问题求救
  • DropDownList数据绑定得问题~~~

关键词

  • .net
  • server
  • ddl1
  • stype
  • pub
  • ui
  • dropdownlist
  • webcontrols
  • connstr
  • selectedindexchanged

得分解答快速导航

  • 帖主:psgogogo

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo