selection in dropdownlist

  • Thread starter Thread starter Ankit Aneja
  • Start date Start date
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());
}
 
DropDownList1.Items.FindByValue(DateTime.Now.ToString("dd")).Selected =
true;

HTH
 
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...
 
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

Back
Top