Thursday, September 15, 2005

add a blank entry to the databind dropdownlist

first of all, keep in mind that adding entry before databinding won't work at all. we should always add the blank entry after binding:

dpQuestion.DataSource = GetQuestions();
dpQuestion.DataTextField = "QSTN_DESC";
dpQuestion.DataValueField = "QSTN_ID";
dpQuestion.DataBind();
//add a blank entry at top
dpQuestion.Items.Insert(0,new ListItem("",""));

No comments: