关于DropDownList

博客展示了获取根类别的代码实现。通过 CategoryManager 类的 getRootCategories 方法,使用 SqlConnection 连接数据库,执行 SQL 查询语句,将结果填充到 DataSet 中,最后返回 DataTable。还在 prepareAddProduct 方法中设置下拉列表的数据源。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

prepareAddProduct

   CategoryManager categoryManager = new CategoryManager();
   DataTable dt = categoryManager.getRootCategories();
   this.DropDownList1.DataSource=dt;
   this.DropDownList1.DataTextField = "categoryName";
   this.DropDownList1.DataBind();

CategoryManager .cs

  public DataTable getRootCategories(){
   SqlConnection l_SqlConnenction = new SqlConnection();
   l_SqlConnenction.ConnectionString = "workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
   l_SqlConnenction.Open();
   string SelectCommandText = "select * from Category";
   SqlCommand l_SqlCommand = new SqlCommand(SelectCommandText,l_SqlConnenction);
   DataSet dataset = new DataSet();;
   SqlDataAdapter adapter = new SqlDataAdapter();
   adapter.SelectCommand = l_SqlCommand;
   adapter.Fill(dataset,"category");
   DataTable dt = dataset.Tables["category"];
   return dt;
   l_SqlConnenction.Close();
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值