Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. DropDownList selected

DropDownList selected

Scheduled Pinned Locked Moved C#
tutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cppdotnet
    wrote on last edited by
    #1

    I have dropdown list with over 50 list item. Based on each selection i want to call a function which populate the DataGrid. Currently, I am doing it following way .. but calling switch case 50 times sounds tidius .. there has to be a better way... seems like it's very common .. for example ... select a State from the dropDownlist and instead of DataGrid they are populating another drpodownlist which is cities in that state. protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e) { string tableName = DropDownList1.SelectedItem.Text; switch (tableName) { case "Address": GetAllAddressData(); break; case "State": GetAllAddressData(); break; ....................... Any ideas or suggestions are really appriciated ... Thanks

    T 1 Reply Last reply
    0
    • C cppdotnet

      I have dropdown list with over 50 list item. Based on each selection i want to call a function which populate the DataGrid. Currently, I am doing it following way .. but calling switch case 50 times sounds tidius .. there has to be a better way... seems like it's very common .. for example ... select a State from the dropDownlist and instead of DataGrid they are populating another drpodownlist which is cities in that state. protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e) { string tableName = DropDownList1.SelectedItem.Text; switch (tableName) { case "Address": GetAllAddressData(); break; case "State": GetAllAddressData(); break; ....................... Any ideas or suggestions are really appriciated ... Thanks

      T Offline
      T Offline
      Tristan Rhodes
      wrote on last edited by
      #2

      As far as i am aware, the standard way of doing it would be have your query / SP text that u will be using to populate your data. On select, read the key out of the selected item, and insert it into your query string, and execute. i.e. protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e) { const int DEFAULT = 0; const string SQL = "EXEC GetStateListByID {1}" int liIndex; string lstrSQL; // Get Key value (Or Tag if Win Forms) liIndex = (int)DropDownList1.SelectedItem.Value; // Exit if default if(liIndex == DEFALT) return; // Format SQL string lstrSQL = string.Format(SQL, liIndex) // Populate DataGrid with results of query this.PopulateDataGrid(lstrSQL); } That's the simple version anyway. Hope it helps. Tris

      C 1 Reply Last reply
      0
      • T Tristan Rhodes

        As far as i am aware, the standard way of doing it would be have your query / SP text that u will be using to populate your data. On select, read the key out of the selected item, and insert it into your query string, and execute. i.e. protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e) { const int DEFAULT = 0; const string SQL = "EXEC GetStateListByID {1}" int liIndex; string lstrSQL; // Get Key value (Or Tag if Win Forms) liIndex = (int)DropDownList1.SelectedItem.Value; // Exit if default if(liIndex == DEFALT) return; // Format SQL string lstrSQL = string.Format(SQL, liIndex) // Populate DataGrid with results of query this.PopulateDataGrid(lstrSQL); } That's the simple version anyway. Hope it helps. Tris

        C Offline
        C Offline
        cppdotnet
        wrote on last edited by
        #3

        Thanks a lot. I am working with n-tier and also Controll - model MSUserInterfaceProcess and from business tier I get dataset back. So I can't use the direct query but this gave me an another idea to try. Thanks a lot again. I was stuck but your suggetion triggered a new thought process. :) Thanks

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups