若您的DropDownList項目來自資料庫, 您可以這麼寫:
DataSet ds = ….;
myDropDownList.DataSource = ds.Tables[0].DefaultView;
myDropDownList.DataTextField=”vDesc”;
myDropDownList.DataValueField=”ID”;
myDropDownList.DataBind();

如果您想在它的第一項再加入新項目,可以在上述程式碼之後再加這行
myDropDownList.Items.Insert(0, new ListItem(”",”")); 

arrow
arrow
    全站熱搜

    包爾伯 發表在 痞客邦 留言(0) 人氣()