Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello, I am using VS2010 with vb.net code. In my project I have a string array. lets simplify it:
Dim arrMyArray(2) as String = {"page1stuff", "page2stuff", "page3stuff"}

I then have a listview to which I want to bind this string array on the click of a button AND have this listview display it (ideally with page numbering - one string item per page). In the click event I have:

ListViewA.DataSource = arrMyArray
ListViewA.DataBind()

Is this enough to bind all the string values from arrMyArray to the listview such that each item becomes a data item in the listview?

2nd part: now, how do I display this? How do I access these new data items. What are they called now? I can't merrily set up a display in the listview control on the aspx page using VS2010 b/c as far as it is concerned, it is not bound to any data (not until runtime when the button is clicked) - can't set up what doesn't exist analogy.

My overall objective here is to get a large string array into a listview so I can leverage page numbering when I have many, many strings/items in my array.

Note: I am using a Listview web server control - not one within system windows...namespace

When I look here it indicates:
http://msdn.microsoft.com/en-us/library/ms178366(v=vs.100).aspx

"The Eval method takes the name of a data field and returns a string containing the value of that field from the current record in the data source."

So my million dollar questions are: can I bind a string array to the listview and what is the name of the data field once I bind it?
Posted
Updated 11-Dec-12 7:04am
v3

1 solution

Hi,

i found some links that looks promising for me,

please have a try with the given solution in below links,

Discussion 1[^]
Discussion 2[^]

Best luck
 
Share this answer
 
Comments
Member 9638729 11-Dec-12 14:43pm    
I've searched for days and looked at stuff like these links to no avail.

I noticed this part of my code does not run... it kicks out of the try:

ListViewA.DataBind()

Maybe you simply cannot bind a string array to a listview? I may have to resort to make an effort to manually code pagination and display the appropriate arrMyArray[x] depending on which page is clicked. Geez, that won't be easy. I'm sure there is an easier way, I just can't figure it out - lack of knowledge.
It will be like building a rocket launcher to exit a cardbox box LOL
AmitGajjar 11-Dec-12 23:57pm    
Yes sometimes it feels like there may be some rocket science :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900