ASP. NET Common collection code 8

Source: Internet
Author: User

/** // <Summary>
/// Make the control focus
/// </Summary>
/// <Param name = "str_ctl_name"> obtain the focus Control ID value, for example, txt_name </param>
/// <Param name = "page"> page class </param>
Public void getfocus (string str_ctl_name, page)
{
Page. registerstartupscript ("", "<SCRIPT> document. forms (0 ). "+ str_ctl_name + ". focus (); document. forms (0 ). "+ str_ctl_name + ". select (); </SCRIPT> ");
}

40. The subform returns the primary form.

/** // <Summary>
/// Name: Redirect
/// Function: The subform returns the primary form.
/// Parameter: URL
/// Return value: NULL
/// </Summary>
Public void redirect (string URL, page)
{
If (session ["ifdefault"]! = (Object) "default ")
{
Page. registerstartupscript ("", "<SCRIPT> Publish topics .doc ument. Location. href = '" + URL + "'; </SCRIPT> ");
}
}

41. Determine if it is a number

/** // <Summary>
/// Name: isnumberic
/// Function: determines whether the input is a number.
/// Parameter: String otext: Source Text
/// Return value: bool true: false: No
/// </Summary>
Public bool isnumberic (string otext)
{
Try
{
Int var1 = convert. toint32 (otext );
Return true;
}
Catch
{
Return false;
}
}

 

Obtain the actual length of a string (including Chinese characters)

// Obtain the actual length of the string ostring
Public int stringlength (string ostring)
{
Byte [] strarray = system. Text. encoding. Default. getbytes (ostring );
Int res = strarray. length;
Return res;
}

42. Convert the carriage return to the tab

// When you press enter on a control with a keydown event, it becomes a tab.
Public void tab (system. Web. UI. webcontrols. webcontrol)
{
Webcontrol. Attributes. Add ("onkeydown", "If (event. keycode = 13) event. keycode = 9 ");
}

43. If the index is exceeded when the page is deleted in the DataGrid

Public void jumppage (system. Web. UI. webcontrols. DataGrid DG)
{
Int int_pageless; // defines the number of page jumps
// If the current page is the last page
If (DG. currentpageindex = DG. The PageCount-1)
{
// If there is only one page
If (DG. currentpageindex = 0)
{
// After deletion, the page is displayed on the current page.
DG. currentpageindex = DG. The PageCount-1;
}
Else
{
// If the last page contains only one record
If (DG. Items. Count % DG. pagesize = 1) | DG. pagesize = 1)
{
// After deleting the last record of the last page, the page should jump to the previous page
Int_pageless = 2;
}
Else // if the number of records on the last page is greater than 1, the records are still on the current page after the last page is deleted.
{
Int_pageless = 1;
}
DG. currentpageindex = DG. pagecount-int_pageless;
}
}
}

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.