Jquery plugin help

Hi experts
I am using a JQuery plugin for selection.
Here is the link.

Instead of select,I am using Listbox with setting its multicolumn to true.

I have a save button by which I save the selected items from the listbox in database.

This is working fine.

Code to bind selected list part
  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;


Now the problem is with validation part,if the selected part has items already in it(bind from database) and user click save,my save query is fired again and the data is duplicated.well I can handle this from sql not to insert but I don't want it to go to my Stopred proc.It should be validated there only.

Another case,if two items are in selected list(bind from database),user remove those items and add different two items,then it should work but if the items present previously are going to save then it should give the message that "Nothing has been changed"
Johny BravoAsked:
Who is Participating?
Hi, Just try to run the attached code.

In my code, MySelectBox is the client ID of the select-box.

If you call ComputeAddDelete function, it will give you two Arrays,
(1) AddedValues = Values, newly checked by the user
(2) RemovedValues = Values, un-checked by the user

Does This helps you?

PS: you can download jquery-1.4.2.min from:

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>

<select multiple id="MySelectBox">
	<option value="1">one</option>
	<option value="2" selected>two</option>
	<option value="3">three</option>
	<option value="4" selected>four</option>
	<option value="5">five</option>
	<option value="6"selected>six</option>
	<option value="7">seven</option>

<button onclick="ComputeAddDelete()">Compute</button>

	var sMySelectBox = "MySelectBox"
	var UserSelection = "";
	var AddedValues = "";
	var RemovedValues = "";

		UserSelection = $("#" + sMySelectBox).val();

	function ComputeAddDelete()
		var userChanges = $("#" + sMySelectBox).val();
		var mySeperator = "<!*^@";
		var joinedVals = "";

		joinedVals = mySeperator + UserSelection.join(mySeperator) + mySeperator;
			if(joinedVals.indexOf(this) == -1)
				AddedValues += mySeperator + this;

		joinedVals = mySeperator + userChanges.join(mySeperator) + mySeperator;
			if(joinedVals.indexOf(this) == -1)
				RemovedValues += mySeperator + this;
		AddedValues = AddedValues.substring(mySeperator.length).split(mySeperator);
		RemovedValues = RemovedValues.substring(mySeperator.length).split(mySeperator);
		alert("Added Value:" + AddedValues + "\n\nRemoved Values:" + RemovedValues);

Open in new window

Send only the selected items from the list box to the stored procedure to insert into database.
Johny BravoAuthor Commented:
Yes that is what I am doing.
But if the user has not done any changes and hit save,then I want to alert him with the message.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

You need to have another listbox or a string which holds the actual values, which the user have not modified.

ie., :
say, you have 1,2...10 items

1. populate the listbox with the already selected values (assume, user have already selected 2,3,4)
now have 2,3,4 in a string.

2. user changed the list, compare in the client-script between the string and the listbox.

3. if user deletes or adds, tell your procedure to do so!

Its as simple as that !

All the best.
Johny BravoAuthor Commented:
Yes here is where I want your help.

1. populate the listbox with the already selected values (assume, user have already selected 2,3,4)
now have 2,3,4 in a string.

2. user changed the list, compare in the client-script between the string and the listbox.
Johny BravoAuthor Commented:
The problem is that when ListBox is populated with Selected items, I have that list in a Viewstate so across postback I can acces the data,
but with Javascript,How can I maintain the list before updating/adding?
Sorry, I am not a guru in .Net, but i can help you in JavaScript.

Please wait, am doing it.
Johny BravoAuthor Commented:
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.