Common operation functions of Asp.net

Source: Internet
Author: User

/// <Summary>
/// Obtain the date of the first day of the week, that is, Sunday.
/// </Summary>
/// <Returns> </returns>
Public static string GetWeekFirstDate ()
{
Return DateTime. Now. AddDays (Convert. ToDouble (0-Convert. ToInt16 (DateTime. Now. DayOfWeek). ToShortDateString ();

}

/// <Summary>
/// Obtain the date of the last day of the week
/// </Summary>
/// <Returns> </returns>
Public static string GetWeekLastDate ()
{
Return DateTime. Now. AddDays (Convert. ToDouble (6-Convert. ToInt16 (DateTime. Now. DayOfWeek). ToShortDateString ();
}

/// <Summary>
/// Convert to Long type. The error is returned.-1
/// </Summary>
/// <Param name = "value"> </param>
/// <Returns> </returns>
Public static long ConvertToLong (object value)
{
Long id =-1;
Long. TryParse (value. ToString (), out id );
Return id;
}
/// <Summary>
/// Convert to Double type, error returns-1
/// </Summary>
/// <Param name = "value"> </param>
/// <Returns> </returns>
Public static double ConvertToDouble (object value)
{
Double id =-1;
Double. TryParse (value. ToString (), out id );
Return id;
}

/// <Summary>
/// Converted to Int type,-1 conversion error
/// </Summary>
/// <Param name = "value"> </param>
/// <Returns> </returns>
Public static int ConvertToInt (object value)
{
Int id =-1;
Int. TryParse (value. ToString (), out id );
Return id;
}
/// <Summary>
/// Bind data to ListControl
/// </Summary>
/// <Param name = "lc"> </param>
/// <Param name = "dt"> </param>
/// <Param name = "strText"> </param>
/// <Param name = "strValue"> </param>
Public static void BindDrop (ListControl lc, DataTable dt, string strText, string strValue)
{
Lc. Items. Clear ();

Foreach (DataRow myRow in dt. Rows)
{
Lc. Items. Add (new ListItem (myRow [strText]. ToString (), myRow [strValue]. ToString ()));
}
Lc. DataBind ();
}

/// <Summary>
/// Bind data to ListControl
/// </Summary>
/// <Param name = "lc"> </param>
/// <Param name = "dt"> </param>
/// <Param name = "strText"> </param>
/// <Param name = "strValue"> </param>
Public static void BindDrop (ListControl lc, DataTable dt, string strText, string strValue, string FirstText, string FirstValue)
{
Lc. Items. Clear ();
Lc. Items. Add (new ListItem (FirstText, FirstValue ));
Foreach (DataRow myRow in dt. Rows)
{
Lc. Items. Add (new ListItem (myRow [strText]. ToString (), myRow [strValue]. ToString ()));
}
Lc. DataBind ();
}

/// <Summary>
/// Bind data to ListControl
/// </Summary>
/// <Param name = "lc"> </param>
/// <Param name = "FirstText"> </param>
/// <Param name = "FirstValue"> </param>
Public static void BindDrop (ListControl lc, string FirstText, string FirstValue)
{
Lc. Items. Clear ();
Lc. Items. Add (new ListItem (FirstText, FirstValue ));
Lc. DataBind ();
}
Public static void BindDataDrop (ListControl list, int iBegin, int iEnd)
{
&

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.