We have finished the "server" side (part 1, part 2) and are ready to write the "client" side of our control.
We face two problems. The first one is to "pass" selected items from the ListBoxFrom to the ListBoxTo (or vice versa) . We will solve it with the help of the client script (JavaScript) . The second problem is to "keep" all "item" changes when clicking some Button server control on the page (this is : "PostBack" event !) and to change the server variables _DT_In and _DT_Out acoording to "item" changes of the ListBox controls. We will solve this problem with the help of four Input(Hidden) controls and the code that we will add to the UserControls_ListBoxesFT_C class. The value of every Input(Hidden) control will consist of items (value or text) of the certain ListBox control, divided by separator (for example : ",") . With the help of the split method we can change these strings (I mean values of the "Hidden") to DataTable, some Array , etc.
Now inside the source of the ListBoxesFT_C.ascx under line:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ListBoxesFT_C.ascx.cs" Inherits="UserControls_ListBoxesFT_C" %>
place the following script:
<script language="javascript" type="text/javascript">
// <!CDATA[
function ButtonHTML_onclick(ListBoxFrom,ListBoxTo,
HiddenToText,HiddenToValue,
HiddenFromText,HiddenFromValue,
bOrderByText,bDoFromList)
{
var iOption;
var iCountHelp;
var iItemList;
var iItemSelect;
var sHelp ;
var iHelp ;
var sForSplit = ":";
var arrList = Array();
var arrListHelp = Array();
var arrHelp = Array();
var sListFrom;
var sListTo;
if (typeof(bDoFromList)== "undefined")
{
bDoFromList=true;
}
else
{
if (typeof(bDoFromList)!= "boolean")
{
bDoFromList=true;
};
};
if (bDoFromList)
{
sListFrom="ListBoxFrom";
sListTo="ListBoxTo";
}
else
{
sListFrom = "ListBoxTo";
sListTo = "ListBoxFrom";
};
if (typeof(bOrderByText )== "undefined")
{
bOrderByText=true;
}
else
{
if (typeof(bOrderByText )!= "boolean")
{
bOrderByText=true;
};
};
iCountHelp=0;
eval("iItemList=" + sListFrom + ".length");
for(iOption=0;iOption< iItemList;iOption++)
{
if (eval(sListFrom+".options[iOption-iCountHelp].selected"))
{
eval("sHelp="+sListFrom+".item(iOption-iCountHelp).text");
eval("iHelp="+sListFrom+".item(iOption-iCountHelp).value");
eval(sListFrom+".remove(iOption-iCountHelp)");
iCountHelp=iCountHelp+1;
eval(sListTo +".options["+sListTo+".length]= new Option(sHelp,iHelp)");
};
};
eval("iItemSelect=" + sListTo+ ".length");
for(iCountHelp=0;iCountHelp<iItemSelect; iCountHelp++)
{
eval("sHelp="+sListTo+".item(iCountHelp).text");
eval("iHelp="+sListTo+".item(iCountHelp).value");
if (bOrderByText)
{
arrList[iCountHelp]= sHelp + sForSplit + iHelp;
}
Join the conversation! Your thoughts help the community grow.