Asp.net is a very useful statement from to 26

Source: Internet
Author: User
21. Custom Exception Handling

// Custom exception handling class
Using system;
Using system. diagnostics;
Namespace myappexception
{
/// <Summary>
/// Application exception handling class inherited from the system exception class applicationexception.
/// Automatically record the exception content to the application logs of Windows NT/2000
/// </Summary>
Public class appexception: system. applicationexception
{
Public appexception ()
{
If (applicationconfiguration. eventlogenabled) logevent (& quot; an unknown error occurs. & Quot ;);
}
Public appexception (string message)
{
Logevent (Message );
}
Public appexception (string message, exception innerexception)
{
Logevent (Message );
If (innerexception! = NULL)
{
Logevent (innerexception. Message );
}
}
// Log record type
Using system;
Using system. configuration;
Using system. diagnostics;
Using system. IO;
Using system. text;
Using system. Threading;
Namespace myeventlog
{
/// <Summary>
/// Event logging class, supporting event logging
/// <Remarks>
/// Defines four logging methods (error, warning, info, trace)
/// </Remarks>
/// </Summary>
Public class applicationlog
{
/// <Summary>
/// Record the error information to the Win2000/NT Event Log
/// <Param name = & quot; message & quot;> text information to be recorded </param>
/// </Summary>
Public static void writeerror (string message)
{
Writelog (tracelevel. error, message );
}
/// <Summary>
/// Record the warning information to the Win2000/NT Event Log
/// <Param name = & quot; message & quot;> text information to be recorded </param>
/// </Summary>
Public static void writewarning (string message)
{
Writelog (tracelevel. Warning, message );
}
/// <Summary>
/// Record the prompt information to the Win2000/NT Event Log
/// <Param name = & quot; message & quot;> text information to be recorded </param>
/// </Summary>
Public static void writeinfo (string message)
{
Writelog (tracelevel. info, message );
}
/// <Summary>
/// Record tracking information to Win2000/NT Event Logs
/// <Param name = & quot; message & quot;> text information to be recorded </param>
/// </Summary>
Public static void writetrace (string message)
{
Writelog (tracelevel. verbose, message );
}
/// <Summary>
/// Format the text information recorded in the event log
/// <Param name = & quot; Ex & quot;> the exception object to be formatted </param>
/// <Param name = & quot; catchinfo & quot;> exception message title string. </param>
/// <Retvalue>
/// <Para> formatted exception information string, including the exception content and trace stack. </para>
/// </Retvalue>
/// </Summary>
Public static string formatexception (exception ex, string catchinfo)
{
Stringbuilder strbuilder = new stringbuilder ();
If (catchinfo! = String. Empty)
{
Strbuilder. append (catchinfo). append (& quot;/R/N & quot ;);
}
Strbuilder. append (ex. Message). append (& quot;/R/N & quot;). append (ex. stacktrace );
Return strbuilder. tostring ();
}
/// <Summary>
/// Actual event log Writing Method
/// <Param name = & quot; level & quot;> level of the information to be recorded (error, warning, info, trace). </param>
/// <Param name = & quot; messagetext & quot;> text to be recorded. </param>
/// </Summary>
Private Static void writelog (tracelevel level, string messagetext)
{
Try
{
Eventlogentrytype logentrytype;
Switch (level)
{
Case tracelevel. Error:
Logentrytype = eventlogentrytype. error;
Break;
Case tracelevel. Warning:
Logentrytype = eventlogentrytype. Warning;
Break;
Case tracelevel. Info:
Logentrytype = eventlogentrytype. Information;
Break;
Case tracelevel. verbose:
Logentrytype = eventlogentrytype. successaudit;
Break;
Default:
Logentrytype = eventlogentrytype. successaudit;
Break;
}
EventLog = new EventLog (& quot; Application & quot;, applicationconfiguration. eventlogmachinename, applicationconfiguration. eventlogsourcename );
// Write Event Logs
EventLog. writeentry (messagetext, logentrytype );
}
Catch {} // ignore any exceptions
}
} // Class applicationlog
}

22. horizontal panel scrolling and vertical auto Scaling

<Asp: Panel style = & quot; overflow-X: Scroll; overflow-Y: auto; & quot;> </ASP: Panel>

23. Press enter to convert to Tab
(1)

<Script language = & quot; JavaScript & quot; For = & quot; Document & quot; event = & quot; onkeydown & quot;>
If (event. keycode = 13 & amp; event. srcelement. type! = 'Button '& amp; event. srcelement. type! = 'Submit '& amp; event. srcelement. type! = 'Reset' & amp; event. srcelement. type! = ''& Amp; event. srcelement. type! = 'Textea ');
Event. keycode = 9;
</SCRIPT>

(2) // 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 (& quot; onkeydown & quot;, & quot; If (event. keycode = 13) event. keycode = 9 & quot ;);
}
24. DataGrid super join Column
Datanavigateurlfield = & quot; field name & quot; datanavigateurlformatstring = & quot; http: // XX/INC/Delete. aspx? Id = {0} & quot;

25. The row of the DataGrid changes color with the mouse

Private void dgzf_itemdatabound (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
If (E. Item. itemtype! = Listitemtype. header)
{
E. item. attributes. add (& quot; onmouseout & quot;, & quot; this. style. backgroundcolor =/& quot; + E. item. style [& quot; Background-color & quot;] + & quot;/& quot ;);
E. item. attributes. add (& quot; onmouseover & quot;, & quot; this. style. backgroundcolor =/& quot; + & quot; # eff3f7 & quot; + & quot;/& quot ;);
}
}

26. template Column

<Asp: templatecolumn visible = & quot; false & quot; sortexpression = & quot; demo & quot;

Headertext = & quot; Id & quot;>
<Itemtemplate>
<Asp label text = '<% # databinder. eval (container. dataitem,

& Quot; ArticleID & quot;) %> 'runat = & quot; server & quot; width = & quot; 80% & quot;

Id = & quot; lblcolumn & quot;/>
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = & quot; Selected & quot;>
<Headerstyle wrap = & quot; false & quot; horiz> <Itemtemplate>
<Asp: checkbox id = & quot; chkexport & quot; runat = & quot; server & quot;/>
</Itemtemplate>
<Edititemtemplate>
<Asp: checkbox id = & quot; chkexporton & quot; runat = & quot; server & quot;

Enabled = & quot; true & quot;/>
</Edititemtemplate>
</ASP: templatecolumn>

Background code

Protected void checkall_checkedchanged (Object sender, system. eventargs E)
{
// Change the column selection to select all or all columns.
Checkbox chkexport;
If (checkall. Checked)
{
Foreach (maid in mydatagrid. Items)
{
Chkexport = (checkbox) odatagriditem. findcontrol (& quot; chkexport & quot ;);
Chkexport. Checked = true;
}
}
Else
{
Foreach (maid in mydatagrid. Items)
{
Chkexport = (checkbox) odatagriditem. findcontrol (& quot; chkexport & quot ;);
Chkexport. Checked = false;
}
}
}

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.