Encounted the issue accident when helping my classmate dealing with his homework assignment,it turns out that I have to consider about 'IsPostBack' when trying to combind the 'DropdownList' in code behind(or it won't get what we expect):
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
Response.Write("<script>alert('Is not PostBack')</script>");
ddlstSinger.Items.Clear();
adapter = new t_musicTableAdapter();
var data = from d in adapter.GetData().AsQueryable()
group d by d.singer
into mySinger
select mySinger.First();
foreach (var d in data) {
ddlstSinger.Items.Add(d.singer);
}
}
}
protected void btnSearch_Click(object sender, EventArgs e) {
if (ddlstSinger.SelectedItem == null) {
Alert("Please enter the search condition!");
return;
}
lbInvisible.Text = ddlstSinger.Text;
lvwSearch.DataSourceID = "ObjectDataSrcSearch";
lvwSearch.DataBind();
}