Set Listbox scroll position after Postback
-
Hi All, I have a muti-select listbox on my web form. When you scroll down to select items and SelectIndexChanged event fires, the postback brings the listbox back to the top of the screen. The item is still selected, but you have to scroll down to see it. How do I get the listbox to show one of the currently selected items. Below is the my code.. aspx page ]]> AutoPostBack="true" Width="150px" OnSelectedIndexChanged="cmdCustomList_SelectedInde xChanged"> client script fuction CustomSelect() { Var SMIndex = document.getElementById('ctl00_ContentPlaceHolder1 _cmdCustomList'); for(var index = 0; index < SMIndex.options.length; index++) { if (SMIndex.options[index].selected) { SMIndex.options[index].selected = true; } } } Code behind protected void cmdCustomList_SelectedIndexChanged(object sender, EventArgs e) int cntSelected = 0; string scriptBlock = "CustomSelect();"; try { if (cmdCustomList.SelectedIndex > -1) { for (int indx = 0; indx<cmdcustomlist.items.count;>{ if (cmdCustomList.Items[indx].Selected == true) { values = values + "," + cmdCustomList.Items[indx].Value; cntSelected++; } } Session["lstCompHosp"] = values; if (chkComparisonExcludeOnly.Checked == false) { if (cntSelected == cmdCustomList.Items.Count) scriptBlock = "cmdAllAvailHosp();" // Another Client side function } updpanelComparisonHospital.Update(); ScriptManager.RegisterStartupScript(this, typeof(DefaultView), "cmdCustom", scriptBlock, true); } } catch (Exception ex) { throw new Exception(ex.Message, ex); } } Would you please give some directions. Thanks Rao
Thanks & Regards Rao
-
Hi All, I have a muti-select listbox on my web form. When you scroll down to select items and SelectIndexChanged event fires, the postback brings the listbox back to the top of the screen. The item is still selected, but you have to scroll down to see it. How do I get the listbox to show one of the currently selected items. Below is the my code.. aspx page ]]> AutoPostBack="true" Width="150px" OnSelectedIndexChanged="cmdCustomList_SelectedInde xChanged"> client script fuction CustomSelect() { Var SMIndex = document.getElementById('ctl00_ContentPlaceHolder1 _cmdCustomList'); for(var index = 0; index < SMIndex.options.length; index++) { if (SMIndex.options[index].selected) { SMIndex.options[index].selected = true; } } } Code behind protected void cmdCustomList_SelectedIndexChanged(object sender, EventArgs e) int cntSelected = 0; string scriptBlock = "CustomSelect();"; try { if (cmdCustomList.SelectedIndex > -1) { for (int indx = 0; indx<cmdcustomlist.items.count;>{ if (cmdCustomList.Items[indx].Selected == true) { values = values + "," + cmdCustomList.Items[indx].Value; cntSelected++; } } Session["lstCompHosp"] = values; if (chkComparisonExcludeOnly.Checked == false) { if (cntSelected == cmdCustomList.Items.Count) scriptBlock = "cmdAllAvailHosp();" // Another Client side function } updpanelComparisonHospital.Update(); ScriptManager.RegisterStartupScript(this, typeof(DefaultView), "cmdCustom", scriptBlock, true); } } catch (Exception ex) { throw new Exception(ex.Message, ex); } } Would you please give some directions. Thanks Rao
Thanks & Regards Rao
Please check whether this link will be useful: http://forums.asp.net/p/1324500/2665985.aspx[^] Regards, Rajdev KR