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

  • Home
  • SEARCH
  • 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 a form in a php application from a C#
I have been trying to do a fill using the open source Srecord Program.
I am trying to fill in a combobox on my winform app from the
I am trying to dynamically fill the Solution right click menu with menu items
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
Im using c# .net windows form application. I have created a database which has
I have a ASP.NET 1.1 application, and I'm trying to find out why when
We are trying to fill our Flex 3 applications background with an image pattern
I'm was trying to fill in a description field when a drop-down was selected.
I'm trying to use jQuery to fill in a form in an iFrame. Do

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.