TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Select Default Value/Text in Dropdownlist in C#
Rajan Singh
May 27
2015
Code
7.6
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<asp:DropDownList ID=
"ddlSize"
runat=
"server"
OnDataBound=
"ddlSize_DataBound"
>
<asp:ListItem Value=
"1"
>S</asp:ListItem>
<asp:ListItem Value=
"2"
>M</asp:ListItem>
<asp:ListItem Value=
"3"
>L</asp:ListItem>
<asp:ListItem Value=
"4"
>XL</asp:ListItem>
<asp:ListItem Value=
"5"
>XXL</asp:ListItem>
</asp:DropDownList>
protected
void
ddlSize_DataBound(
object
sender, EventArgs e)
{
if
(ddlSize !=
null
)
{
if
(ddlSize.Items.FindByText(
"1"
) !=
null
)
{
ddlSize.Items.FindByValue(
"1"
).Selected =
true
;
}
}
}
OR
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!ispostback)
{
ddlSize.Items.FindByValue(
"1"
).Selected =
true
;
}
}
DropdownList