Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set a default item in a listbox?

Status
Not open for further replies.

cmn2

Programmer
Mar 6, 2003
73
US
Greetings

I have a asp:listbox where I would like to have the first item selected when the page is first rendered, but I'm not sure how to do this. Could anyone help me on this?

Thank you

<ASP:ListBox id="lstCompany" runat="server" Width="90" Height="80">
<ASP:ListItem Value="1">MyCompany</ASP:ListItem>
<ASP:ListItem Value="2">YourCompany</ASP:ListItem>
<ASP:ListItem Value="3">TheirCompany</ASP:ListItem>
</ASP:ListBox>
 
If it's the same as a normal drop down

<select name="Choice">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>

Then you should be able to put in the word 'SELECTED' on the first item eg:

<option value="a" SELECTED>a</a>
 
Set Forum = Tek-tips.ASP.NET forum


Cheers

QatQat

Life is what happens when you are making other plans.
 
Didn't realize there was an asp.net forum too.
I posted there.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top