Personal Web development experience (7) ---- very suitable for beginners and common sense

Source: Internet
Author: User

 

61.

The Difference and usage between ref and out (the function is the same, but the out does not need to initialize ref first)

The ref keyword allows the parameter to be passed by reference. The effect is that when the control is passed back to the call method, any changes made to the parameters in the method will be reflected in the variable. To use the ref parameter, you must explicitly use the ref keyword for both method definition and call methods. For example:

Copy code
Class refexample
{
Static void method (ref int I)
{
I = 44;
}
Static void main ()
{
Int val = 0;/******** different from ref and out ***********/
Method (ref Val );
// Val is now 44
}
}
 
Parameters passed to the ref parameter must be initialized first. Unlike out, out parameters do not need to be explicitly initialized before being passed. (

Class outexample
{
Static void method (Out int I)
{
I = 44;
}
Static void main ()
{
Int value;/********* different from ref and out ***********/
Method (out value );
// Value is now 44
}
}

 

62. Obtain the absolute path of the page
String strurl = request. url. absolutepath;

63. Note that the year and month are case-insensitive during conversion.
Return datatime. tostring ("yyyy-mm-dd hh: mm: SS ");

64. Use or and for SQL statements
Select * From wlog where pid = '20160901' and ldate = '2017-06-30 'or pid = '20160901' and ldate = '2017-06-29'
That is to say, the conditions for grouping with or are grouped with and as a group.

65. The between statement is used to retrieve the records between the time and time of the optimized date.
Select * From wlog where pid = '20170101' and ldate between '2017-06-25 'and '2017-06-30' and PID = '2016030'

66. Find the control checkboxlist in the gridview
Sqldatareader SDR = SC. executereader (commandbehavior. closeconnection );

(Checkboxlist) datagrid1.findcontrol ("checkboxlist2"). datasource = SDR;
(Checkboxlist) datagrid1.findcontrol ("checkboxlist2"). datatextfield = "permission name ";
(Checkboxlist) datagrid1.findcontrol ("checkboxlist2"). databind ();

Find a node in the Treeview

String notepath = "value of top-level note \ value of second-layer note \ value of Third-layer note ";

If (treeview1.findnode (notepath )! = NULL)
Treeview1.findnode (notepath). Checked = true;

67. Hide the primary key field in the gridview
First bind the field to the gridview
Set the field ID to the datakeyname attribute of the gridview

Use
For (INT I = 0; I <gridview1.rows. Count; I ++)
Gridview1.datakeys [I]. value. tostring ();

68. If the query record is null, 0 is returned.
Select name, isnull (select num from B where name = A. Name), 0) from

Isnull (select num from B where name = A. Name), 0)

If the SELECT statement is null, 0 is returned.

69. If you click a row in the DataGrid, the row will be colored to select a row of records for processing.
Private void datagrid_itemcreated (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
If (E. item. itemtype = listitemtype. ITEM) | (E. item. itemtype = listitemtype. alternatingitem) | (E. item. itemtype = listitemtype. selecteditem ))
{
E. Item. Attributes. Add ("onmouseover", "This. style. backgroundcolor = '# bed3e9'; this. style. cursor = 'hand '");
E. Item. Attributes. Add ("onmouseout", "This. style. backgroundcolor = 'white ';");
}
}

70. The data format remains unchanged when importing pure numbers into Excel
The solution is to use the Excel features

View examples

Code

<% @ Page Language = "C #" autoeventwireup = "true" %>
<SCRIPT runat = "server">
Void page_load (Object sender, system. eventargs E)
{
String data1 = "000000001 ";
Long data2 = 123456789123456789;
System. Io. stringwriter Sw = new system. Io. stringwriter ();
Sw. writeline ("original digit 1 \ t converted digit 1 \ t original digit 2 \ t converted digit 2 ");
For (INT I = 0; I <10; I ++)
{
SW. writeline (data1 + "\ t" + "= \" "+ data1 +" \ "\ t" + data2 + "\ t" + "= \" "+ data2.tostring () + "\"");
}
Sw. Close ();
Response. Buffer = true;
Response. charset = "";
Response. appendheader ("content-disposition", "attachment?filename=aa.xls ");
Response. contenttype = "application/MS-excel"; // set the output file type to an Excel file.
Response. contentencoding = system. Text. encoding. getencoding ("gb2312"); // set the output stream to simplified Chinese
Response. Write (SW );
Response. End ();
 
}
</SCRIPT>

 

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.