如何在下拉列表框中添加“所有项”选项

 

//获得所有论坛名称并填入下接列表中

                string sql;

                OleDbDataReader dr;

                sql="SELECT forumid, forumname FROM forum  ORDER BY forumid";

                OleDbCommand cmd;

                OleDbConnection con=new OleDbConnection(ConfigurationSettings.AppSettings["con.ConnectionString"]);

                cmd=new OleDbCommand(sql,con);

                con.Open();

 

                dr=cmd.ExecuteReader();

 

                this.ddlForumName.Items.Add(new ListItem("所有论坛", "0"));

                while(dr.Read())

                {

                    ListItem li=new ListItem(dr["forumname"].ToString(),dr["forumid"].ToString());

                    this.ddlForumName.Items.Add(li);

                    if(li.Value==sforumid)

                    {

                        this.ddlForumName.SelectedValue=li.Value ;

                    }

                }

       

                dr.Close();

                con.Close();

posted @ 2005-06-11 13:05  虚空境界  Views(586)  Comments(0Edit  收藏  举报