Hello, I have a form with two dropdown form fields. The user wants to have the selectedvalue prepolated: DDLFrom needs to be preselected to yesterday's value, the DDLTo needs to be preselected to today's date. Here is the catch: the dropdown fields are dynamically loaded from a table and only displays the dates where an issue was logged.
See attached screenshot. So my question is for the DDLFrom I need the closest date to yesterday and for DDLTo needs to be the most recent date.
This code throws an error since there was no today's date nor was there a date for yesterday since it was the weekend and so no activities.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Me.ddlFrom.SelectedValue = DateTime.Now.AddDays(-1).ToString("MM/dd/yyyy")
Me.ddlTo.SelectedValue = DateTime.Now.ToString("MM/dd/yyyy")