如何让一个DropDownList绑定值后默认值为空,设置默认选中值

SqlConnection con = new SqlConnection("server=.;uid=sa;database=pubs");
        SqlDataAdapter sdr = new SqlDataAdapter("select * from employee",con);
        DataSet ds = new DataSet();
        sdr.Fill(ds);
        DropDownList1.DataSource = ds;
        DropDownList1.DataTextField = "emp_id";
        DropDownList1.DataBind();
        DropDownList1.Items.Add(" ");
        DropDownList1.Items[this.DropDownList1.Items.Count - 1].Value = " ";
        DropDownList1.SelectedIndex = this.DropDownList1.Items.Count - 1;


                1.

       ListItem wxlx_item = wxlx.Items.FindByValue(sdr.GetValue(10).ToString().Trim());
                    if (wxlx_item != null)
                    {
                        wxlx_item.Selected = true;
                    }

       2.

       DropDownList1.SelectedIndex = this.DropDownList1.Items.Count - 1;

posted @ 2012-05-31 14:44  cziger  阅读(6301)  评论(0编辑  收藏  举报