日历

2008 8.21 Thu
     12
3456789
10111213141516
17181920212223
24252627282930
31      
«» 2008 - 8 «»

文章搜索

日志文章

2007年06月15日 12:20:07

ASP.NET中填充下拉列表的值

本来其实是很简单的问题,不知道脑袋是进水了,还是怎么了,搞了很长时间才弄明白
现在把它记录在这,万一以后再忘记怎么办?
一. SqlDataReader填充下拉列表
    string str = "select bigName from bigClass";
    Conn.SelectClass select = new Conn.SelectClass();
    SqlDataReader read = select.myTable(str);
    while (read.Read())
    {
      string item = "";
      for (int i = 0; i < read.FieldCount; i++)
      {
        item += read.GetValue(i);
       
      }
      this.comLeiBie1.Items.Add(item);
    }

二.DataSet 填充下拉列表的值
comLeiBie2为下拉列表的名字
string big=this.comLeiBie1.SelectedItem.ToString();
    string str = "select distinct smallName from smallClass inner join bigClass on smallClass.bigId=(select id from bigClass where bigName='" + big + "' )";

    Conn.SelectClass select = new Conn.SelectClass();
    DataSet ds = select.getDataSet(str);
    this.comLeiBie2.Items.Clear();
   
    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
    {
      this.comLeiBie2.Items.Add(ds.Tables[0].Rows["smallName"].ToString());
     
     
    }

Tags: SqlDataReader  

类别: ASP.NET |  评论(1) |  浏览(5031) |  收藏
发表评论