c# - Dropdownlist selected item text always returning the first item text -


i using code fill dropdownlist database.

public void fillcountry() {     bl obj = new bl();     dataset ds = obj.dss("select * country  ");     drplistcountry.datasource = ds;     drplistcountry.datatextfield = "countryname";     drplistcountry.datavaluefield = "countryid";     drplistcountry.databind();     drplistcountry.items.insert(0, new listitem("--select--", "0")); } 

i using fillcountry() in page load() event. , rerutning selecteditm.text on button click event

drplistcountry showing first index text , how solve it?

in .aspx page:

<%@ page title="home page" language="c#" autoeventwireup="true" codebehind="default.aspx.cs" inherits="webapplication4._default"  enableviewstate="true" %> 

for dropdownlist control set enableviewstate property true.

in .aspx.cs page:

in pageload event check following:

if(!ispostback) {      fillcountry(); } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -