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來解決