DropDownList中在數據綁定後如何插入第一項提示

       Links link = new Links();
        SqlDataReader dr = null;
        dr = link.GetLinks();
        DropDownList1.DataSource = dr;
        DropDownList1.DataTextField = "LinkName";
        DropDownList1.DataValueField = "LinkID";
        DropDownList1.DataBind();

            ListItem al = new ListItem("<--選擇一個-->", "0");
            al.Selected = true;
            DropDownList1.Items.Insert(0, al);

 

其中Link是我寫的一個類,返回的是一個 DataReader,其中LinkName還有LinkID各自綁定。

在綁定後,我希望在DropDownList第一個被選擇的是提示<--選擇一個-->那麼就用

上面的方法Items.Insert來解決 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章