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. for each loop - add item to listbox

for each loop - add item to listbox

Scheduled Pinned Locked Moved ASP.NET
helpdesignregex
7 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.
  • E Offline
    E Offline
    eyeseetee
    wrote on last edited by
    #1

    Hi I was talking about somethign similar on the 2nd page but thought better to start a new post in case no one looked on the 2nd page :) Basically i have a for loop and in it I need to add items to a listbox I have the following but I am getting an error message: foreach (DataRow row in dataSetactorder.Tables[0].Rows) { listboxact.Items.Add (row[0]); } error: " The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments " any help would be great cheers :)

    N P 2 Replies Last reply
    0
    • E eyeseetee

      Hi I was talking about somethign similar on the 2nd page but thought better to start a new post in case no one looked on the 2nd page :) Basically i have a for loop and in it I need to add items to a listbox I have the following but I am getting an error message: foreach (DataRow row in dataSetactorder.Tables[0].Rows) { listboxact.Items.Add (row[0]); } error: " The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments " any help would be great cheers :)

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      .netman wrote:

      The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments

      The error message clear enough. It requires a string type, but you are supplying DataRow. It could be something like

      foreach (DataRow row in dataSetactorder.Tables[0].Rows)
      {
      listboxact.Items.Add (row[0].ToString());
      }

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

      modified on Wednesday, April 9, 2008 4:54 AM

      E 1 Reply Last reply
      0
      • N N a v a n e e t h

        .netman wrote:

        The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments

        The error message clear enough. It requires a string type, but you are supplying DataRow. It could be something like

        foreach (DataRow row in dataSetactorder.Tables[0].Rows)
        {
        listboxact.Items.Add (row[0].ToString());
        }

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        modified on Wednesday, April 9, 2008 4:54 AM

        E Offline
        E Offline
        eyeseetee
        wrote on last edited by
        #3

        ok ive filled up the listbox and now I want to check if any of the values in the listbox match a value from a text box WHat is the best way to do this ive got the following - stallactorder being the string result from the listbox and updateact the string value from the textbox How can i assign the values from a listbox to a string, or is there a better way to do it? pesudo code would be if listbox contains a value which matches textbox { } actual code so far if (stallactorder.Trim().Contains(updateact)) any help would be great cheers! :)

        N U 2 Replies Last reply
        0
        • E eyeseetee

          ok ive filled up the listbox and now I want to check if any of the values in the listbox match a value from a text box WHat is the best way to do this ive got the following - stallactorder being the string result from the listbox and updateact the string value from the textbox How can i assign the values from a listbox to a string, or is there a better way to do it? pesudo code would be if listbox contains a value which matches textbox { } actual code so far if (stallactorder.Trim().Contains(updateact)) any help would be great cheers! :)

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          I think you are following to my reply for your last post yesterday. In that I haven't meant to use a list box. I was suggesting to use List<string> class. It has a Contains() method and you can take the string easily from it.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

          1 Reply Last reply
          0
          • E eyeseetee

            ok ive filled up the listbox and now I want to check if any of the values in the listbox match a value from a text box WHat is the best way to do this ive got the following - stallactorder being the string result from the listbox and updateact the string value from the textbox How can i assign the values from a listbox to a string, or is there a better way to do it? pesudo code would be if listbox contains a value which matches textbox { } actual code so far if (stallactorder.Trim().Contains(updateact)) any help would be great cheers! :)

            U Offline
            U Offline
            Usharva
            wrote on last edited by
            #5

            Hi!! try the below code for (int i = 0; i <= ListBox1.Items.Count - 1; i++) { if (ListBox1.Items[i].ToString() == TextBox1.Text) { //your statement } }

            E 1 Reply Last reply
            0
            • U Usharva

              Hi!! try the below code for (int i = 0; i <= ListBox1.Items.Count - 1; i++) { if (ListBox1.Items[i].ToString() == TextBox1.Text) { //your statement } }

              E Offline
              E Offline
              eyeseetee
              wrote on last edited by
              #6

              cheers that sorted my problem thanks!! I decided not to use the string method nav you discussed as I knew the listbox a bit more thanks :)

              1 Reply Last reply
              0
              • E eyeseetee

                Hi I was talking about somethign similar on the 2nd page but thought better to start a new post in case no one looked on the 2nd page :) Basically i have a for loop and in it I need to add items to a listbox I have the following but I am getting an error message: foreach (DataRow row in dataSetactorder.Tables[0].Rows) { listboxact.Items.Add (row[0]); } error: " The best overloaded method match for 'System.Web.UI.WebControls.ListItemCollection.Add(string)' has some invalid arguments " any help would be great cheers :)

                P Offline
                P Offline
                Paddy Boyd
                wrote on last edited by
                #7

                Why are you not just databinding to the table?

                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