Carlo Adap
Carlo Adap

Reputation: 35

Displaying List<Datetime> to a Listbox

DateTime StartDate = Convert.ToDateTime(txtDate.Text);
DateTime EndDate = Convert.ToDateTime(TextBox1.Text);


List<DateTime> datetimerange = new List<DateTime>();
while (DateTime.Compare(StartDate, EndDate) <= 0)
{
    datetimerange.Add(StartDate);
    StartDate = StartDate.AddDays(1);
}

how can i display the list of dates and display it to listbox?

Thanks in advance

Upvotes: 1

Views: 1964

Answers (3)

Mahdi Tahsildari
Mahdi Tahsildari

Reputation: 13582

foreach (var datetime in datetimerange)
{
     listBox1.Items.Add(datetime.ToString());
}

Upvotes: 0

seeker
seeker

Reputation: 3333

Lstbox.DataSource=datetimerange

Where Lstbox is ListBox object

Upvotes: 0

Waqar Janjua
Waqar Janjua

Reputation: 6123

Suppose, I have a listbox with ID lb; just set it's DataSource property equal to your datetime list and call the list.DataBind method.

 List<DateTime> datetimerange  = new List<DateTime>();
 lb.DataSource = datetimerange ;
 lb.DataBind();

Upvotes: 2

Related Questions