I have a list box which is populated via migrating items from another list box. I have 2 asp.net buttons namely Up and Down to scroll up and down through the list box. The maximum number of items visible at a time in the list box is 9, while the maximum number of items are 21. Hence a scrollbar comes eventually. Its pretty evident and ok. Now if I select the 21st item and click on Up button, the 21st item moves to one place above, but the list shows items from the first. I mean to say that the list is rearranged, and the client has to explicitly scroll down the list box to view the 21st item which has been moved above.
I want that if I select an item and click the Up button, view of the list box should be there itself, it shouldn't show the list box from the very first item.
Any help would be appreciated.
Below is my code:
protected void btnThird_Click(object sender, EventArgs e)
{
if (lstBoxSelectedColumns.SelectedIndex == 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alertScrollUp", "alertMessage('Please select other item to scroll up or click the Down navigation button');", true);
}
else if (lstBoxSelectedColumns.SelectedIndex > 0)
{
for (int i = 0; i < lstBoxSelectedColumns.Items.Count; i++)
{
if (lstBoxSelectedColumns.Items[i].Selected)
{
if (i > 0 && !lstBoxSelectedColumns.Items[i - 1].Selected)
{
ListItem belowItem = lstBoxSelectedColumns.Items[i];
lstBoxSelectedColumns.Items.Remove(belowItem);
lstBoxSelectedColumns.Items.Insert(i-1, belowItem);
lstBoxSelectedColumns.Items[i - 1].Selected = true;
}
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alertSelectAtleastOneItem2", "alertMessage('Please select at least one item to scroll above');", true);
}
}
Regards
Anurag