[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

'string' does not contain a definition for 'Items'

Posted on 2016-09-22
8
Medium Priority
?
44 Views
Last Modified: 2016-09-23
I get the myCustomParameterValue as a dynamic value when user clicks on a button. the value is a string, and I need to assign it so it has Items property (I am not sure if I explain it correctly).  But as you can see, "myCustomParameterValue" has been used, I am not sure how I can assign it.  Thanks

            string myCustomParameterValue = attributColl["CustomParameter"];

            testBox.Text = myCustomParameterValue;

            ListBox myCustomParameterValue = new ListBox();
            foreach (var item in myCustomParameterValue.Items.Cast<ListItem>().Reverse())
            {
              //  mainlist.Items.Add(item);
              //  myCustomParameterValue.Items.Remove(item);
            }

Open in new window

0
Comment
Question by:mcrmg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 20

Expert Comment

by:Russ Suter
ID: 41811486
In your code you are creating an instance of a string and assigning it to the variable named myCustomParameterValue. Later you are creating an instance of a ListBox control and assigning it to a variable of the same name. The foreach loop has nothing to do since the ListBox you just created has no items associated.
0
 

Author Comment

by:mcrmg
ID: 41811502
The first myCustomParameterValue is a string and I need to assign it to a ListBox control so it can be used in foreach loop.  Is there a way to do it?  thanks
0
 
LVL 20

Expert Comment

by:Russ Suter
ID: 41811511
You cannot assign a single string value to be the data source of a ListBox control. That doesn't actually make much sense. If you could do that then you'd have a LIstBox which contains exactly one item. If your string is delimited in some way, like with a comma, you could split on that character and create a string[] object. The string array could then be set as the DataSource property of the ListBox control.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mcrmg
ID: 41811521
I see.  That string is actually a CustomParameter from a button. I just want to have this function to be shared by different buttons instead of creating several functions that are doing the same thing.
0
 
LVL 20

Accepted Solution

by:
Russ Suter earned 2000 total points
ID: 41811528
I see no reason why you can't call this function from multiple origins. The issue is that you need to have some sort of collection, be it a simple array, a List<> object, or something that implements the IEnumerable interface and then use the DataSource property of the ListBox control to assign that collection. If your input is a single string that is OK but you'd need to put it into a List<string> or a string[] array. A list or array containing only one item is perfectly legitimate. Something like this (off the top of my head)
string[] testData = new string[] { "Hello world" };
ListBox myListBox = new ListBox();
myListBox.DataSource = testData;
... etc ...

Open in new window

0
 

Author Comment

by:mcrmg
ID: 41811537
my boss is kicking everyone out now...I will try it in the AM and post back..thank you
0
 

Author Comment

by:mcrmg
ID: 41811548
This is what I did real quick, it looks like fireach is empty. But if I replace "myListBox" as name of listbox, the code works..thanks

string[] testData = new string[] { myCustomParameterValue };
            ListBox myListBox = new ListBox();
            myListBox.DataSource = testData;

            foreach (var item in myListBox.Items.Cast<ListItem>().Reverse())
            {
                mainlist.Items.Add("Sally");
                mainlist.Items.Add(item);
                myListBox.Items.Remove(item);
            }

Open in new window

0
 

Author Closing Comment

by:mcrmg
ID: 41812527
Thank you very much.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question