selection in dropdownlist

A

Ankit Aneja

i am displaying days of month
and want that today day should be selected by default how can i do that

DateTime str;
str=DateTime.Now;
int DayToday=str.Day;
for(int i=1;i<=31;i++)
{
DropDownList1.Items.Add(i.ToString());
}
 
G

Grant Merwitz

DropDownList1.Items.FindByValue(DateTime.Now.ToString("dd")).Selected =
true;

HTH
 
M

Mark Rae

i am displaying days of month
and want that today day should be selected by default how can i do that

DateTime str;
str=DateTime.Now;
int DayToday=str.Day;
for(int i=1;i<=31;i++)
{
DropDownList1.Items.Add(i.ToString());
}

Something like:
DropDownList1.Items.FindByText(DayToday.ToString()).Selected = true;

N.B. This is just from memory, so you may have to tweak it a bit...
 
A

Ankit Aneja

solved like this
for(int i=1;i<=31;i++)

{

DropDownList1.Items.Add(i.ToString());

}

DropDownList1.SelectedValue =DayToday.ToString();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top