Live Chat Icon For mobile
Live Chat Icon

How to make the listbox scroll down to show it’s last entry when the page loads?

Platform: ASP.NET| Category: ListBox

<p>
<asp:ListBox id='ListBox1' runat='server'></asp:ListBox>
</p>
<p>
<asp:Button id='buttonAdd'  runat='server' Text='Add'></asp:Button>
</p>

In button Click Event

VB.NET


ListBox1.Items.Add(DateTime.Now.ToString('MMM dd, yyyy') + ' ' + DateTime.Now.ToString('t'))
Dim scrollScript As String
scrollScript &= '<script language=’javascript’>'
scrollScript &= 'document.forms[0].ListBox1.selectedIndex ' & _
          ' = document.forms[0].ListBox1.options.length-1;'
scrollScript &= '<' & '/' & 'script>'
Page.RegisterStartupScript('', scrollScript)

C#


ListBox1.Items.Add(DateTime.Now.ToString('MMM dd, yyyy') + ' ' + DateTime.Now.ToString('t'));
string scrollScript='' ;
scrollScript += '<script language=’javascript’>';
scrollScript += 'document.forms[0].ListBox1.selectedIndex  = document.forms[0].ListBox1.options.length-1;';
scrollScript += '<' + '/' + 'script>';
Page.RegisterStartupScript('', scrollScript);

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.