ArrayList and ViewState in C#

G

Guest

Hi

I have a listbox with multiple values. I want to store those selected values in an arraylist. I am not sure how to write the arraylist with ViewState in C#. The following code is the string datatype, not arraylist.

My questions ar

1. How to modify string SelectedDeptIDs to be an arraylist with ',' to be delimiter to store all selected listitems
2. How can I retrieve those values in arraylist (splite with ',' to be delimiter) when postback? Do I use Items.Clear() and Items.Add()

[code
protected string SelectedDeptID

ge

return ViewState["SelectedDeptIDs"] == null? "":(string)ViewState["SelectedDeptIDs"]

se

ViewState["SelectedDeptIDs"] = value



foreach (System.Web.UI.WebControls.ListItem li in listDept.Items

if (li.Selected

SelectedDeptIDs = li.Value


[/code

Thanks for help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top