1. Open a new window and transfer the parameters:
Transfer parameters:
Response.Write ("")
Receive parameters:
String a = Request.QueryString ("id"); String B = Request.QueryString ("Id1");
2. Add a dialog box for the button
BUTTON1.ATTRIBUTES.ADD ("onclick", "return confirm (' confirmation? ')"); Button.attributes.add ("onclick", "If" (Confirm (' Is you sure ...? ')) {return true;} Else{return false;} ")
3. Delete table Selected records
int intempid = (int) Mydatagrid.datakeys[e.item.itemindex]; String deletecmd = "DELETE from Employee where emp_id =" + intempid.tostring ()
4. Delete a table record warning
private void datagrid_itemcreated (Object sender,datagriditemeventargs e) {switch (e.item.itemtype) {case ListItemType . Item:case ListItemType.AlternatingItem:case ListItemType.EditItem:TableCell Mytablecell; Mytablecell = e.item.cells[14]; LinkButton Mydeletebutton; Mydeletebutton = (LinkButton) mytablecell.controls[0]; MYDELETEBUTTON.ATTRIBUTES.ADD ("onclick", "return confirm (' Are you sure you want to delete this message ');"); Break Default:break; } }
5. Click the table row link to another page
private void Grdcustomer_itemdatabound (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {//Click Table to open if (E.item.itemtype = = ListItemType.Item | | e.item.itemtype = = listitemtype.alternatingitem) e.Item.Attributes.Add (" OnClick "," window.open (' default.aspx?id= "+ e.item.cells[0]. Text + "');"); Double-click the table to connect to another page in the ItemDataBind event if (E.item.itemtype = = ListItemType.Item | | e.item.itemtype = = ListItemType.AlternatingItem) {string Orderitemid =e.item.cells[1]. Text; ... e.item.attributes.add ("ondblclick", "location.href="). /shippedgrid.aspx?id= "+ orderitemid +" ' ");} Double-click the table to open a new page if (E.item.itemtype = = ListItemType.Item | | e.item.itemtype = = listitemtype.alternatingitem) {string OrderItem ID =e.item.cells[1]. Text; ... e.item.attributes.add ("ondblclick", "Open (')". /shippedgrid.aspx?id= "+ Orderitemid +" ') "); }
6. Table Hyperlink Column Pass Parameters
' & Name= ' <%# DataBinder.Eval (Container.DataItem, "data field 2")%> '/>
7. Click to change the color of the table
if (E.item.itemtype = = ListItemType.Item | | E.item.itemtype = = ListItemType.AlternatingItem) {e.item.attributes.add ("onclick", "this.style.backgroundcolor=" # 99cc00 '; This.style.color= ' ButtonText '; this.style.cursor= ' default '; '); Write in the _itemdatabound of the datagrid if (E.item.itemtype = = ListItemType.Item | | E.item.itemtype = = ListItemType.AlternatingItem) {e.item.attributes.add ("onmouseover", "This.style.backgroundColor = ' #99cc00 '; This.style.color= ' ButtonText '; this.style.cursor= ' default '; "); E.item.attributes.add ("onmouseout", "this.style.backgroundcolor="; this.style.color= ";");
8. About date formats
Date format setting dataformatstring= "{0:YYYY-MM-DD}" I think I should e.items.cell["your column"].text=datetime.parse in the Itembound event (e.items.cell[ "Your column"].text. ToString ("Yyyy-mm-dd"))
9. Get the error message and go to the specified page
Do not use Response.Redirect, but should use Server.Transfer
e.g
In global.asax protected void Application_Error (Object sender, EventArgs e) {if (Server.GetLastError () is Httpunhandle dexception) Server.Transfer ("myerrorpage.aspx"); The remaining non-httpunhandledexception exceptions are given to ASP. Okay:)} REDIRECT will cause the Post-back to lose the error message, so the page guidance should be executed directly on the server side, so that the error message can be obtained and processed accordingly.
10. Empty Cookies
Cookie.expires=[datetime]; Response.Cookies ("UserName"). Expires = 0
11. 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. Automatic logging of exception content to Windows nt/2000 Application Log///</summary> public class AppException:System.ApplicationException {public Ap Pexception () {if (applicationconfiguration.eventlogenabled) LogEvent ("An unknown error occurred. "); Public appexception (String message) {LogEvent (message); Public appexception (String message,exception innerexception) {LogEvent (message); if (innerexception! = null) {LogEvent (innerexception.message); }}//log record class using System; Using System.Configuration; Using System.Diagnostics; Using System.IO; Using System.Text; Using System.Threading; namespace MyEventLog {////<summary>///Event logging classes, providing event logging support///<remarks>////////////////////////define 4 Trace)///</remarks>//</summary> public class Applicationlog {///<summary>//error message logged to WIN2000/NT event day Zhi Zhong//<param name= "message"> text information that needs to be recorded </param>//</summary> public static void Writeerror (String message) {Writelog (TraceLevel.Error, message); }////<summary> Log warning messages to the Win2000/nt event Log///<param name= "message" and text information required for recording </param>//</summary> Publ IC static void writewarning (String message) {Writelog (tracelevel.warning, message); }////<summary>///To log the message to the Win2000/nt event Log///<param name= "message" and the text information required for recording </param>//</summary> Publ IC static void Writeinfo (String message) {Writelog (tracelevel.info, message); }////<summary>///To log trace information to the Win2000/nt event Log///<param name= "message" and text information required for recording </param>//</summary> Publ IC static void Writetrace (String message) {Writelog (tracelevel.verbose, message); }/////<summary> format the text information format logged to the event Log///<param Name= "Ex" > need to format the exception object </param>//<param name= "Catchinfo" > exception information The header string. </param>//<retvalue>//<para> format exception information string, including exception content and trace stack. </para>//</retvalue> </summary> public static string FormatException (Exception Ex, string catchinfo) {StringBuilder Strbuilde R = new StringBuilder (); if (catchinfo! = String.Empty) {strbuilder.append (catchinfo). Append ("\ r \ n"); } strbuilder.append (ex. Message). Append ("\ r \ n"). Append (ex. StackTrace); return strbuilder.tostring (); }////<summary>////<param Name= "level" to log information levels (ERROR,WARNING,INFO,TRACE). </param>//<param Name= "MessageText" > The 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 EventLog = new EventLog ("Application", Applicationconfiguration.eventlogmachinename, Applicationconfigurat Ion. Eventlogsourcename); Write Event Log EventLog.WriteEntry (MessageText, Logentrytype); } catch {}//ignore any exceptions}}//class Applicationlog}