vb.net - Show Selected Item in Listbox (System.Web.UI.WebControls) -
I am working with a listbox, say, 20 items list box size, allow user to see first 5 items gives. However, there is a pre-selected item in the listbox that is sometimes not visible because it is not one of the first 5 items.
How can I ensure that the lisbox is scrolled appropriately after listing the selected items for list so that the selected items appear to the user?
Thank you for your help!
Have you tried setting up TopIndex property?
listBox.TopIndex = itemindex;
Sorry, my first understanding of your question was completely wrong. I think you can do it using Javascript. I tested the sample on Windows 7 and IE8 and it worked.
& lt;% @ Page language = "C #" AutoEventWireup = "true" CodeFile = "Default.aspx.cs" Inherits = "_Default"% & gt; & Lt ;; DOCTYPE HTML PUBLIC "- // W3C // DTT XHTML 1.0 Transcription // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Head runat = "server" & gt; & Lt; Title & gt; & Lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Function setScindedX () {var listbox = $ get ('listbox'); Var text box = $ received ('text box'); Listbox.selectedIndex = textbox.value; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form id = "form1" runat = "server" & gt; & Lt; Div & gt; & Lt; Asp: ScriptManager id = "ScriptManager1" runat = "server" & gt; & Lt; / ASP: ScriptManager & gt; & Lt; ASP: List box run = "server" id = "list box" & gt; & Lt; Asp: ListItem text = "A" value = "A" /> & Lt; Asp: ListItem text = "B" value = "b" /> & Lt; Asp: ListItem text = "C" value = "C" /> & Lt; Asp: ListItem text = "D" value = "D" /> & Lt; Asp: ListItem text = "E" value = "E" /> & Lt; Asp: ListItem text = "F" value = "F" /> & Lt; Asp: ListItem text = "G" value = "g" /> & Lt; Asp: ListItem text = "h" value = "h" /> & Lt; Asp: ListItem text = "I" value = "I" /> & Lt; Asp: ListItem text = "K" value = "K" /> & Lt; / ASP: ListBox & gt; & Lt; ASP: Text Box Runat = "Server" id = "Text Box" Text = "8" /> & Lt; ASP: Button Runat = "server" id = "button" text = "select" OnClientClick = "set selectedindex (); return back;" / & Gt; & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Comments
Post a Comment