Validate DateTime

public static bool ValidateDateFormat(string sDate)
{
     bool isValid = true;
 
     DateTime Test;
     string[] formats = { "MM/dd/yyyy""M/d/yyyy""M/dd/yyyy""MM/d/yyyy" };
     if (!DateTime.TryParseExact(sDate, formats, new CultureInfo("en-US"), 
DateTimeStyles.None, out Test))      {         isValid = false;      }      //      return isValid; } public static DateTime ConvertDate(string sDate) {   string[] formats = { "M/d/yyyy""MM/dd/yyyy""M/dd/yyyy""MM/d/yyyy" };   DateTime tDate;   DateTime.TryParseExact(sDate, formats, new CultureInfo("en-US"),
DateTimeStyles.None, out tDate);   return tDate; }

e.Row.RowState == DataControlRowState.Edit not works on Alternating Rows

Problem:

The combine Alternatiing/Edit state fail the comparsion logic.

Solution:

if ((e.Row.RowState & DataControlRowState.Edit) > 0)

ListControl AppendDataBoundItems Property

Here is a example:

<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server" DataSourceID="SqlDataSource1" DataTextField="country" DataValueField="country">

<asp:ListItem Text="(Select a Country)" Value="" />

</asp:DropDownList>

You can setup an initial value -- such as an initial "(Select a Country)" that are not part of the databound result. Because the "AppendDataBoundItems" property is set to true, after databinding it will then have a dropdownlist whose first value is "(Select a Country)" followed by the data you bound to the list control.