Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4110640
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:57:37+00:00 2026-05-20T21:57:37+00:00

hi m trying fill the combo box from cities database but i wan the

  • 0

hi m trying fill the combo box from cities database but i wan the metropolitan cities at the top of the selection menu
i have used this approach i there any alternative??

For metros:

            List<Lst_City> lstCity= new List<Lst_City>();
            lstCity = new BFCommon().getCities();
            lstCity[0].CityID = 474;
            lstCity[0].CityNM = "Mumbai";
            lstCity[1].CityID = 199;
            lstCity[1].CityNM = "Delhi";
            lstCity[2].CityID = 165;
            lstCity[2].CityNM = "Chennai";
            lstCity[3].CityID = 384;
            lstCity[3].CityNM = "Kolkata";
            lstCity[4].CityID = 582;
            lstCity[4].CityNM = "Pune";
            lstCity[5].CityID = 71;
            lstCity[5].CityNM = "Bangalore";
            lstCity[6].CityID = 306;
            lstCity[6].CityNM = "Hyderabad";
            lstCity[7].CityID = 11;
            lstCity[7].CityNM = "Ahmedabad";

Dropdown binding:

ddCities.DataSource = lstCity;
ddCities.DataTextField = "CityNM";
ddCities.DataValueField = "CityID";
ddCities.DataBind();
ddCities.Items.Insert(0, new ListItem("Select One", string.Empty));

Query:

public List<Lst_City> getCities()
        {
            List<Lst_City> temp = (from e in objCommonDataContext.Lst_Cities
                                       where e.inUse == true
                                       select e).ToList();

            return temp;

        }

and the combo box in designer

<div class="row">
    <label>
    City :</label>
    <ajaxToolkit:ComboBox ID="ddCities" runat="server" AutoPostBack="False"
     DropDownStyle="DropDownList"
     AutoCompleteMode="SuggestAppend"
     CaseSensitive="False"
     CssClass=""
     ItemInsertLocation="Append" Width="380px"></ajaxToolkit:ComboBox>

am achieving the purpose but it doesn’t seems ideal since hard coded and also entries are repeated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:57:38+00:00Added an answer on May 20, 2026 at 9:57 pm

    It seems from your code, all the cities are in a table.
    My suggestion is:
    Add a new column may be IsMetropolital

    List<Lst_City> temp = (from e in objCommonDataContext.Lst_Cities
                                           where e.inUse == true && e.IsMetropolital==false
                                           select e).ToList();
    
    List<Lst_MetroCity> tempMetro = (from e in objCommonDataContext.Lst_Cities
                                           where e.inUse == true && e.IsMetropolital=true
                                           select e).ToList();
    
    List<Lst_City> lstCity= new List<Lst_City>();
    
    
    foreach(var t in tempMetro) 
    {
      // Add cities to the lstCity
    }
    
    foreach(var t in temp) 
    {
      // Add cities to the lstCity
    }
    

    Now finally populate set the datasource of the dropdown with lstCity as you have done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to fill up an NSmutableAray with data from sqlite database. ItemShow
I am trying to populate a combo box with data but I cant get
I'm trying to fill the dropdown on run time from the database, whenever user
I am trying to fill out a DataGridView with data from a database. The
I am just trying to fill my ListView but I get a NullPointerException Here
I am trying to Fill a formula that I have in D1 and fill
I'm trying to fill an array of 20 ints with numbers from 1-20 in
I am trying to fill object[] with List<string> but I cannot figure out how
I'm trying to fill a grid view using data from a db cursor using
I have some classes and I'm trying to fill the objects of this class.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.