c# - problem with drop down list -
i have drop down list control populated items , code take selected item value. problem value of first item in list regardless of item selected.
here code populate drop down:
protected void displaycreatecategories() { storedatacontext db = new storedatacontext(); var = c in db.categories orderby c.name select new{catname= c.name, catid=c.categoryid}; ddlcategory.datasource = a; ddlcategory.datatextfield = "catname"; ddlcategory.datavaluefield = "catid"; ddlcategory.databind(); } to value of selected item in case of type integer label1.text=convert.toint32(ddlcategory.selectedvalue);
selected value, 1st item in list. i'm pulling hair out on this. :(
i suspect you're running list loading code every time page loads, destroying list, repopulating list, , auto-selecting first item before selection retrieval code gets run.
use construction in page_load:
if (!ispostback) { // initial control population goes here }
Comments
Post a Comment