Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dropdownlis name ddlcountry -> select
USA
India
AUS

which the ddlcountry data is binding from database.

Source code
C#
if (!IsPostBack)
{
   Filldata();
   loadpage();
}

public void Filldata()
{
   DataTable Dt = objdatahandler.Getallcountry();

   ddlCountry.DataSource = Dt;
   ddlCountry.DataTextField = "CountryName";
   ddlCountry.DataValueField = "CountryID";
   ddlCountry.DataBind();
   ddlCountry.Items.Insert(0, new ListItem("Select", "0"));
}
       
public void loadpage()
{
   int regaid = Convert.ToInt32(Request.QueryString["id"]);
   objcomreg.regid = regaid;
   DataTable Dt = objdatahandler.getcountbyid(objcomreg);
            
   if (Dt.Rows.Count > 0)
   {
      ddlCountry.SelectedValue = Dt.Rows[0]["Country"].ToString();
   }
}


when iam editing i am always getting the first value only in the dropdownlist , it is not showing the value
Posted
Updated 24-Nov-14 21:47pm
v3
Comments
Sajith Koleri 25-Nov-14 4:38am    
use below code in if condition
ddlCountry.SelectedValue = Dt.Rows[0]["CountryID"].ToString();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900