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. Web Development
  3. ASP.NET
  4. dropdown list

dropdown list

Scheduled Pinned Locked Moved ASP.NET
helpquestion
11 Posts 4 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.
  • P Offline
    P Offline
    ptvce
    wrote on last edited by
    #1

    i have one dropdown list and i bind it but: i want the content of dropdown list be Id and name like: 1203/Frank can u help me???????

    E V 2 Replies Last reply
    0
    • P ptvce

      i have one dropdown list and i bind it but: i want the content of dropdown list be Id and name like: 1203/Frank can u help me???????

      E Offline
      E Offline
      enjoycrack
      wrote on last edited by
      #2

      Hi there, You can change your datasource before binding it to ddl, you might have to change the SQL query to something like "select id+'/'+name...." Anyway you should check the query again as I'm not sure if it's correct or not :laugh: << >>

      P 1 Reply Last reply
      0
      • E enjoycrack

        Hi there, You can change your datasource before binding it to ddl, you might have to change the SQL query to something like "select id+'/'+name...." Anyway you should check the query again as I'm not sure if it's correct or not :laugh: << >>

        P Offline
        P Offline
        ptvce
        wrote on last edited by
        #3

        hi thats not right i did that in asp.net(c#). what should i write in this code insted of * dropdownlist.datatextfield = "*";

        E V 2 Replies Last reply
        0
        • P ptvce

          hi thats not right i did that in asp.net(c#). what should i write in this code insted of * dropdownlist.datatextfield = "*";

          E Offline
          E Offline
          enjoycrack
          wrote on last edited by
          #4

          hi I dont know about this solution, but IMO if selecting datatextfield="*", that means all fields will be shown in ddl, right? if so, what is the delimeter between these fields? Re. my suggestion, I think it's also correct as you just select 2 fields (id and name) and combine these into one field as your format, then just bind the combined field to ddl (SQL: select id+'/'+name as combinedfield....) << >>

          1 Reply Last reply
          0
          • P ptvce

            hi thats not right i did that in asp.net(c#). what should i write in this code insted of * dropdownlist.datatextfield = "*";

            V Offline
            V Offline
            VaibhavJ
            wrote on last edited by
            #5

            Hi, I think u can do it in Asp.NET and also in the SQL query. I just tried the same. Here it is... SELECT ct.intUSCityId, ct.strUSCityName,CAST(ct.intUSCityId AS VARCHAR(50)) + '/' + ct.strUSCityName AS Vaib ,ct.isDeleted FROM tbCity AS ct WHERE ct.intUSCountyId=10 To bind it to the dropdownlist DropdownList.DataTextField = "Vaib"; DropdownList.DataValueField = "intUSCityId"; The other one ofcourse by concatenating ID+ "/" + "Name" in Asp.NET It's working fairly well. So, I think u can use any of these methods Thanks for reading, Vaibhav :)

            1 Reply Last reply
            0
            • P ptvce

              i have one dropdown list and i bind it but: i want the content of dropdown list be Id and name like: 1203/Frank can u help me???????

              V Offline
              V Offline
              VaibhavJ
              wrote on last edited by
              #6

              Hi, I think u must be returning a DataSet to bind it to the dropdown containing "ID" and "Name"...You can do following to display "ID/Name" to DropdownList where ID & Name are column names u return through ur query. if(ds!=null && ds.Tables.Count > 0) { if( ds.Tables[0].Rows.Count > 0) { ds.Tables[0].Columns.Add("strDisplay",typeof(System.String)); for(int i = 0 ; i < ds.Tables[0].Rows.Count;i++) { ds.Tables[0].Rows[i]["strDisplay"] = ds.Tables[0].Rows[i]["ID"] +"/" + ds.Tables[0].Rows[i]["Name"] ; } } } And to bind the dropdownlist DropdownList.DataTextField = "strDisplay"; DropdownList.DataValueField = "Value"; I think this should work fine... Thank u, Vaibhav

              E P 2 Replies Last reply
              0
              • V VaibhavJ

                Hi, I think u must be returning a DataSet to bind it to the dropdown containing "ID" and "Name"...You can do following to display "ID/Name" to DropdownList where ID & Name are column names u return through ur query. if(ds!=null && ds.Tables.Count > 0) { if( ds.Tables[0].Rows.Count > 0) { ds.Tables[0].Columns.Add("strDisplay",typeof(System.String)); for(int i = 0 ; i < ds.Tables[0].Rows.Count;i++) { ds.Tables[0].Rows[i]["strDisplay"] = ds.Tables[0].Rows[i]["ID"] +"/" + ds.Tables[0].Rows[i]["Name"] ; } } } And to bind the dropdownlist DropdownList.DataTextField = "strDisplay"; DropdownList.DataValueField = "Value"; I think this should work fine... Thank u, Vaibhav

                E Offline
                E Offline
                enjoycrack
                wrote on last edited by
                #7

                yes sure it should work, but to be more efficient you can do this from SQL query....No need to load data into dataset and loop over all records in dataset to create the third column :cool::cool: << >>

                V 1 Reply Last reply
                0
                • E enjoycrack

                  yes sure it should work, but to be more efficient you can do this from SQL query....No need to load data into dataset and loop over all records in dataset to create the third column :cool::cool: << >>

                  V Offline
                  V Offline
                  VaibhavJ
                  wrote on last edited by
                  #8

                  ya..That's a useful advice... Thanks a lot..:-D

                  R 1 Reply Last reply
                  0
                  • V VaibhavJ

                    ya..That's a useful advice... Thanks a lot..:-D

                    R Offline
                    R Offline
                    RSArockiam
                    wrote on last edited by
                    #9

                    You can use expression column in datatable. In this method, no need to loop through all the records. Regards R.Arockiapathinathan

                    V 1 Reply Last reply
                    0
                    • R RSArockiam

                      You can use expression column in datatable. In this method, no need to loop through all the records. Regards R.Arockiapathinathan

                      V Offline
                      V Offline
                      VaibhavJ
                      wrote on last edited by
                      #10

                      Thanks a lot.. I tried this one and it's really very good solution. Thanks a lot for the help. Thanks & regards, Vaibhav :)

                      1 Reply Last reply
                      0
                      • V VaibhavJ

                        Hi, I think u must be returning a DataSet to bind it to the dropdown containing "ID" and "Name"...You can do following to display "ID/Name" to DropdownList where ID & Name are column names u return through ur query. if(ds!=null && ds.Tables.Count > 0) { if( ds.Tables[0].Rows.Count > 0) { ds.Tables[0].Columns.Add("strDisplay",typeof(System.String)); for(int i = 0 ; i < ds.Tables[0].Rows.Count;i++) { ds.Tables[0].Rows[i]["strDisplay"] = ds.Tables[0].Rows[i]["ID"] +"/" + ds.Tables[0].Rows[i]["Name"] ; } } } And to bind the dropdownlist DropdownList.DataTextField = "strDisplay"; DropdownList.DataValueField = "Value"; I think this should work fine... Thank u, Vaibhav

                        P Offline
                        P Offline
                        ptvce
                        wrote on last edited by
                        #11

                        thanks for your help yes thats right.:rose:

                        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