ViewState and ListBox

Hi Experts,

I am having a ListBox,thae data of which I want to store in the ViewState (multicolumn Listbox).I want to know that if user has changed the values in the listbox on Save event.

  private void FillSelectedRole(int siteId,int levelId)
        {
            //ViewState["SelectedItemCount_"] = 0;
            SkillUpdateRight skUpdateRights = new SkillUpdateRight();
            Dictionary<object, object> dictRoleSelected = skUpdateRights.GetSelectedRole(siteId,levelId);
           
            foreach (KeyValuePair<object, object> kvp in dictRoleSelected)
            {
                ListItem li = new ListItem(kvp.Value.ToString(), kvp.Key.ToString());
                li.Selected = true;
                lstRole.Items.Add(li);

              //How to store items in viewstate
            }

protected void imgbtnSave_Command(object sender, CommandEventArgs e)
        {
            //How to check previous items in viewstate and newly selected items
           
           
        }
LVL 8
Johny BravoAsked:
Who is Participating?
 
alainbrydenCommented:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox_events.aspx

Implement the appropriate ListBox Changed event. It's as simple as checking for a change in that event, and setting a property to true. Then when they hit the save command, you can check if that property is true, deal with the changes, and then set it back to false for next time.

--
Alain
0
 
Johny BravoAuthor Commented:
I think I haven't explained well.
I have a listbox populated from db.
I want to hold these items in the viewstate.
There is another listbox,with which user can add or remove the items for first Listbox.
I need to check if the user has changed the previous List.
0
 
alainbrydenCommented:
You can still use the listbox change event to detect that.

--
Alain
0
 
Johny BravoAuthor Commented:
Hi alainbryden
I am using a JQuery plugin for listbox
Here is the link.
http://michael.github.com/multiselect/index.html?countries%5B%5D=AFG&countries%5B%5D=DZA&countries%5B%5D=ARG&countries%5B%5D=ABW&countries%5B%5D=AUT&countries%5B%5D=BGD

So the listbox is a single control having two parts, available list and selected list.
there is no event fired as it is a jqery plugin.

any other idea?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.