I have two listboxes in my aspx page,which i called them ListBox1 and ListBox2.
I set the datasource of ListBox1 in pageload but ListBox2 is empty.
protected void btnSubmit_Click(object sender, EventArgs e)
{
for (int count = 0; count <= Convert.ToInt32(lbright.Items.Count); count++)
{
string str = null;
string[] strArr = null;
int count2 = 0;
str = lbright.Items[count].ToString();
char[] splitchar = { ';' };
strArr = str.Split(splitchar);
for (count2 = 0; count2 <= strArr.Length - 1; count++)
{
Response.Write(
"Option" + count + ":<br />" +
" " + "Value" + count2 + ":" + strArr[count]
);
}
}
}
The user can double click on items in ListBox1 to add them to ListBox2.I have wrote this code in JQuery.Everything works fine in this part.
<script type="text/javascript">
$(document).ready(function () {
$('#lbleft').on('dblclick', 'option', function () {
var element = $("#lbleft option:selected");
var value = element.val();
var text = element.text();
element.remove();
$("#lbright").append('<option value="' + value + '">' + text + '</option>');
});
$('#lbright').on('dblclick', 'option', function () {
var element = $("#lbright option:selected");
var value = element.val();
var text = element.text();
element.remove();
$("#lbleft").append('<option value="' + value + '">' + text + '</option>');
});
});
The problem is when i want to read items from ListBox2.
I have a button in my page which user can save items of ListBox2 by clicking on this button.but the count of items of ListBox2 is zero in codebehind.