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
  1. Home
  2. Web Development
  3. ASP.NET
  4. put two field in listbox

put two field in listbox

Scheduled Pinned Locked Moved ASP.NET
7 Posts 3 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 want fill listbox with to coulmn of data,first column be id and secend column be name,we fill list box this form: ... ... listbox.datatextfield = "name"; ... ... but this form i have one column in listbox can i do this work ... .. listbox.datatextfield = "id" + "name"; .. .. -- modified at 10:14 Tuesday 28th February, 2006

    A 1 Reply Last reply
    0
    • P ptvce

      i want fill listbox with to coulmn of data,first column be id and secend column be name,we fill list box this form: ... ... listbox.datatextfield = "name"; ... ... but this form i have one column in listbox can i do this work ... .. listbox.datatextfield = "id" + "name"; .. .. -- modified at 10:14 Tuesday 28th February, 2006

      A Offline
      A Offline
      Anish Gopi
      wrote on last edited by
      #2

      Hai, Its not possible to bind multiple coloums to ListBox. To do so you need to loop through data and do things manually.

      Eg:
      foreach(DataRow row in tblUser.Rows)
      {
      ListItem itm = new ListItem(row["id"] + row["name"], row[id);
      listbox.Items.Add(itm);
      }

      P 1 Reply Last reply
      0
      • A Anish Gopi

        Hai, Its not possible to bind multiple coloums to ListBox. To do so you need to loop through data and do things manually.

        Eg:
        foreach(DataRow row in tblUser.Rows)
        {
        ListItem itm = new ListItem(row["id"] + row["name"], row[id);
        listbox.Items.Add(itm);
        }

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

        can you say to me how can do this work with c#????? how can write sql cod that concat two field(two columns)

        H A 2 Replies Last reply
        0
        • P ptvce

          can you say to me how can do this work with c#????? how can write sql cod that concat two field(two columns)

          H Offline
          H Offline
          HimaBindu Vejella
          wrote on last edited by
          #4

          Use + operator for contatenation in C# The code posted by Anish was self Explanatory Even u can use DataSet and Adapter to bind to list Senior Software Engineer

          P 1 Reply Last reply
          0
          • H HimaBindu Vejella

            Use + operator for contatenation in C# The code posted by Anish was self Explanatory Even u can use DataSet and Adapter to bind to list Senior Software Engineer

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

            i done this work and it is right. but i want to be a distance between them such as a to column for example: id-----------name 1------------aaaa 2------------bbbb 3------------cccccccc 123----------eeeeeeee -- modified at 0:45 Wednesday 1st March, 2006

            H 1 Reply Last reply
            0
            • P ptvce

              can you say to me how can do this work with c#????? how can write sql cod that concat two field(two columns)

              A Offline
              A Offline
              Anish Gopi
              wrote on last edited by
              #6

              Hai, String Concatenation is quite simple in C# with the use of + operator,

              eg:
              string tmp = row["id"] + " ------" + row["name"];

              We can also do the code with much more redabilty like,

              string tmp = string.Format("{0} ----- {1}", row["id"], row["name"]);

              1 Reply Last reply
              0
              • P ptvce

                i done this work and it is right. but i want to be a distance between them such as a to column for example: id-----------name 1------------aaaa 2------------bbbb 3------------cccccccc 123----------eeeeeeee -- modified at 0:45 Wednesday 1st March, 2006

                H Offline
                H Offline
                HimaBindu Vejella
                wrote on last edited by
                #7

                Just append the ---- in your sql query select name+'-------'+address as Details from persons and we can bind the details column to the dropdownlist. Senior Software Engineer Nothing is Impossible Even Impossible says I'MPOSSSIBLE -- modified at 0:43 Friday 24th March, 2006 "Aim to go where U have never been B4 and Strive to achieve it" http://groups.yahoo.com/subscribe/dotnetforfreshers http://himabinduvejella.blogspot.com

                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