how to set default null value in combobox

12,475

Try this:

ddlfrom.Items.Insert(0, "Select...");

Like this:

dr = new MySqlDataAdapter("select tvl_code, concat_ws(',', tvl_code, citi_name) citiname from code_desc where travel_mode = 'BUS'", conn);
ds1 = new DataSet();
dr.Fill(ds1);
ddlfrom.DataSource = ds1;
ddlfrom.DataTextField = "citiname";
ddlfrom.DataValueField = "tvl_code";
ddlfrom.DataBind();
ddlfrom.Items.Insert(0, "Select...");
Share:
12,475
Naveen31
Author by

Naveen31

Updated on June 04, 2022

Comments

  • Naveen31
    Naveen31 almost 2 years
    dr = new MySqlDataAdapter("select tvl_code, 
       concat_ws(',', tvl_code, citi_name) citiname 
       from code_desc where travel_mode = 'BUS'", conn);
    ds1 = new DataSet();
    dr.Fill(ds1);
    ddlfrom.DataSource = ds1;
    ddlfrom.DataTextField = "citiname";
    ddlfrom.DataValueField = "tvl_code";
    ddlfrom.DataBind();
    

    by this code i am binding my combobox to the database and i am able to populate the combobox from my database.But when i am opening the page the combobox contains one value by default from the database..means the first name from database list from where i am populating is shown on combobox..I want to show blank on the combobox..means it should not show anything printed until i will select some thing from dropdown.How to do that..??

  • Naveen31
    Naveen31 over 10 years
    i did that..not getting..actually all the city names in the database are in alphabetical oredr..and in the same order it is showing in my dropdownlist also...but by default when i am opening or running that page then..the first city in the database starting with "A" is printed on the box..and i want to show that box empty by default...
  • Samiey Mehdi
    Samiey Mehdi over 10 years
    @Naveen31 try my answer
  • शेखर
    शेखर over 10 years
    @Naveen31 use <asp:ListItem Text="" Value="-1" />