Saturday, March 24, 2012

ListBox

I have a web service that returns a list of records. I can read through the records with

for (int ii=0; ii< result.olineSequence.Length; ii++)
{
ListBox1.Items.Add(result.olineSequence[ii].name);
ListBox1.Items.Add(result.olineSequence[ii].city);
}

As you can see there are 2 columns of data. I want to present the data in a list of some sort on my asp page and allow selection of a row. I don't know if a listbox is the best way. Also above code puts name(1) on the first line, city(1) on the second line of listbox but I want them to be in columns.

Can anyone help please?It's not pretty but:

for (int ii=0; ii< result.olineSequence.Length; ii++)

{

ListBox1.Items.Add(result.olineSequence[ii].name + ", " + result.olineSequence[ii].city);

}

For a neater list, you could use a DataList, but its not as compact as a DDL.
Thanks for the reply. This gives me a list eg.

Jack,London
Jim,New York
Sam,Australia

Is there anything I can do in the listbox setup to show different columns with grid lines and headers?
the web ddl doesnt support multicolumn.

you could use a fixed pitch font and then insert spaces between the two values so that the second set of text items stays left aligned.

I believe you'd need to insert the extra spaces as non-breaking to keep them from collapsing. for a ddl, you may need to use chr(160) instead of

if you did that, you could insert one extra row at position zero to act as a psuedo header...

there are also solutions out there that allow you to put datagrids etc... inside scrolling divs.
this allows you to have a long list of items, but only show a reasonable portion. That type of solution gives you much better column and formatting control...
FYI, there are some good third-party controls that will do this for you. Of course I'm partial toEasyListBox...

Cheers,

0 comments:

Post a Comment