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. can we bind datatextfield and datavaluefield in a dropdownlist using for loop in asp.net(code behind)

can we bind datatextfield and datavaluefield in a dropdownlist using for loop in asp.net(code behind)

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
9 Posts 2 Posters 1 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.
  • M Offline
    M Offline
    M Ramesh
    wrote on last edited by
    #1

    hai I want to bind DataTextField and DataValueField for dropdownlist in code behind of asp.net application. anybody help.. Regards M.Ramesh

    S 1 Reply Last reply
    0
    • M M Ramesh

      hai I want to bind DataTextField and DataValueField for dropdownlist in code behind of asp.net application. anybody help.. Regards M.Ramesh

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      I think this can be get from Google Check google you will find n number of articles that will show this this is basic, you need to learn how to learn Let me know if you get any difficulties while implementing this Atleast show some efforts :)

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

      M 1 Reply Last reply
      0
      • S Sandeep Akhare

        I think this can be get from Google Check google you will find n number of articles that will show this this is basic, you need to learn how to learn Let me know if you get any difficulties while implementing this Atleast show some efforts :)

        Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

        M Offline
        M Offline
        M Ramesh
        wrote on last edited by
        #3

        hai friend, I think that you didn't got my query. ie.if it is dataset means i will bind directly like mydataset.tables(0) like that but I am having data like "1,sandeep|2,Ramesh|3,Akhare". So I need to bind in the dropdownlist using for loop. I need answer for this.. Thanks & Regards M.Ramesh

        S 1 Reply Last reply
        0
        • M M Ramesh

          hai friend, I think that you didn't got my query. ie.if it is dataset means i will bind directly like mydataset.tables(0) like that but I am having data like "1,sandeep|2,Ramesh|3,Akhare". So I need to bind in the dropdownlist using for loop. I need answer for this.. Thanks & Regards M.Ramesh

          S Offline
          S Offline
          Sandeep Akhare
          wrote on last edited by
          #4

          OK Its more simple just create a IDictionary with key values and bind that one to your drop downlist in page_init event like this public class Test { public static IDictionary GetBusinessStates() { IDictionary StateTable = new System.Collections.Specialized.OrderedDictionary(); StateTable.Add(" ", "Select One"); StateTable.Add("Sa", "Sandeep"); StateTable.Add("Ra", "Ramesh"); StateTable.Add("Ak", "Akhare"); return StateTable; } } Write this in Page_Init DropDownList1.DataSource = Test.GetBusinessStates(); DropDownList1.DataTextField = "Value"; DropDownList1.DataValueField = "Key"; DropDownList1.DataBind();

          Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

          M 1 Reply Last reply
          0
          • S Sandeep Akhare

            OK Its more simple just create a IDictionary with key values and bind that one to your drop downlist in page_init event like this public class Test { public static IDictionary GetBusinessStates() { IDictionary StateTable = new System.Collections.Specialized.OrderedDictionary(); StateTable.Add(" ", "Select One"); StateTable.Add("Sa", "Sandeep"); StateTable.Add("Ra", "Ramesh"); StateTable.Add("Ak", "Akhare"); return StateTable; } } Write this in Page_Init DropDownList1.DataSource = Test.GetBusinessStates(); DropDownList1.DataTextField = "Value"; DropDownList1.DataValueField = "Key"; DropDownList1.DataBind();

            Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

            M Offline
            M Offline
            M Ramesh
            wrote on last edited by
            #5

            hai friend, Thanks for your needful help. I need which namespace for IDictionary ie.using System.Collections like that.. Thanks & Regards M.Ramesh.

            S 1 Reply Last reply
            0
            • M M Ramesh

              hai friend, Thanks for your needful help. I need which namespace for IDictionary ie.using System.Collections like that.. Thanks & Regards M.Ramesh.

              S Offline
              S Offline
              Sandeep Akhare
              wrote on last edited by
              #6

              Just use using System.Collections; Let me know if your problem get resolved

              Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

              M 1 Reply Last reply
              0
              • S Sandeep Akhare

                Just use using System.Collections; Let me know if your problem get resolved

                Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                M Offline
                M Offline
                M Ramesh
                wrote on last edited by
                #7

                The following is the code, iam getting error ie.specified cast is not valid.. Dim lDataRow() as DataRow lDataRow = ldstDataset.Tables(2).Select("GroupID='" & lintGroupId & "'") lDtTable = GetVouItems(lDataRow) Public Function GetVouItems(ByVal pgDataRow() As DataRow) As IDictionary Dim StateTable As New System.Collections.Specialized.NameValueCollection Dim lDataRow() As DataRow Dim lintCnt As Integer lDataRow = pgDataRow For lintCnt = 0 To lDataRow.Length - 1 StateTable.Add(lDataRow(lintCnt)(1), lDataRow(lintCnt)(2)) Next Return StateTable End Function

                S 1 Reply Last reply
                0
                • M M Ramesh

                  The following is the code, iam getting error ie.specified cast is not valid.. Dim lDataRow() as DataRow lDataRow = ldstDataset.Tables(2).Select("GroupID='" & lintGroupId & "'") lDtTable = GetVouItems(lDataRow) Public Function GetVouItems(ByVal pgDataRow() As DataRow) As IDictionary Dim StateTable As New System.Collections.Specialized.NameValueCollection Dim lDataRow() As DataRow Dim lintCnt As Integer lDataRow = pgDataRow For lintCnt = 0 To lDataRow.Length - 1 StateTable.Add(lDataRow(lintCnt)(1), lDataRow(lintCnt)(2)) Next Return StateTable End Function

                  S Offline
                  S Offline
                  Sandeep Akhare
                  wrote on last edited by
                  #8

                  Sorry now i can't help you As you have written in VB i don't understand its very difficult BOSS

                  Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                  M 1 Reply Last reply
                  0
                  • S Sandeep Akhare

                    Sorry now i can't help you As you have written in VB i don't understand its very difficult BOSS

                    Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                    M Offline
                    M Offline
                    M Ramesh
                    wrote on last edited by
                    #9

                    hai friend, i can surely do it using ur concept..thanks a lot.. Regards M.Ramesh

                    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