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
Post a Comment