Jquery plugin help

Hi experts
I am using a JQuery plugin for selection.
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

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;
                lstRole.Items.Add(li);

             
            }

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"
LVL 8
Johny BravoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SriVaddadiCommented:
Send only the selected items from the list box to the stored procedure to insert into database.
0
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.
0
StealthyDevCommented:
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.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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.
0
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?
0
StealthyDevCommented:
Sorry, I am not a guru in .Net, but i can help you in JavaScript.

Please wait, am doing it.
0
StealthyDevCommented:
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?

Regards.
PS: you can download jquery-1.4.2.min from:
http://jquery.com/

<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>
</select>

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

<script>
	var sMySelectBox = "MySelectBox"
	var UserSelection = "";
	var AddedValues = "";
	var RemovedValues = "";

	$(document).ready(function(){
		UserSelection = $("#" + sMySelectBox).val();
	});

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

		joinedVals = mySeperator + UserSelection.join(mySeperator) + mySeperator;
		$(userChanges).each(function(){
			if(joinedVals.indexOf(this) == -1)
				AddedValues += mySeperator + this;
		});

		joinedVals = mySeperator + userChanges.join(mySeperator) + mySeperator;
		$(UserSelection).each(function(){
			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);
	}
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Johny BravoAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.