1. open a new window and send parameters:
Transfer Parameters:
Response. Write ("<SCRIPT> window. Open ('*. aspx? Id = "+ this. dropdownlist1.selectindex +" & id1 = "+... +" ') </SCRIPT> ")
Receiving parameters:
String A = request. querystring ("ID ");
String B = request. querystring ("id1 ");
2. Add dialog box for button
Button1.attributes. Add ("onclick", "Return confirm ('OK? ')");
Button. Attributes. Add ("onclick", "If (confirm ('Are you sure ...? ') {Return true;} else {return false ;}")
3. Delete selected table records
Int intempid = (INT) mydatagrid. datakeys [E. Item. itemindex];
String deletecmd = "delete from employee where emp_id =" + intempid. tostring ()
4. Delete 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 information ');");
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 Open Table
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 a 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 a table to open a new page.
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
String orderitemid = E. Item. cells [1]. text;
...
E. Item. Attributes. Add ("ondblclick", "open ('../shippedgrid. aspx? Id = "+ orderitemid + "')");
}
★Note :【? Id =] cannot be 【? Id =]
6. Table hyperjoin column Transfer Parameters
<Asp: hyperlinkcolumn target = "_ blank" headertext = "ID" datatextfield = "ID" navigateurl = "AAA. aspx? Id = '<% # databinder. eval (container. dataitem, "data field 1") %> '& 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 ';");
}
Written in _ 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 Format
Date Format setting
Dataformatstring = "{0: yyyy-mm-dd }"
I think it should be in the itembound event
E. items. cell ["your column"]. TEXT = datetime. parse (E. items. cell ["your column"]. text. tostring ("yyyy-mm-dd "))
9. Get error information and go to the specified page
Instead of using response. Redirect, you should use server. Transfer
E. g
// In Global. asax
Protected void application_error (Object sender, eventargs e ){
If (server. getlasterror () is httpunhandledexception)
Server. Transfer ("myerrorpage. aspx ");
// Other non-httpunhandledexception exceptions are handed over to ASP. NET for processing and okay.
}
Redirect will cause post-back generation and thus the loss of error information, so the page orientation should be executed directly on the server side, so that the error processing page can be
Obtain error information and process it accordingly.
10. Clear 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.
/// 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 ("an unknown error occurs. ");
}
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 = "message"> 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 = "message"> 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 = "message"> 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 = "message"> 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 = "ex"> the exception object to be formatted </param>
/// <Param name = "catchinfo"> 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 ("/R/N ");
}
Strbuilder. append (ex. Message). append ("/R/N"). append (ex. stacktrace );
Return strbuilder. tostring ();
}
/// <Summary>
/// Actual event log Writing Method
/// <Param name = "level"> information level (error, warning, info, trace) to be recorded. </param>
/// <Param name = "messagetext"> 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 ("application", applicationconfiguration. eventlogmachinename, applicationconfiguration. eventlogsourcename );
// Write Event Logs
EventLog. writeentry (messagetext, logentrytype );
}
Catch {} // ignore any exceptions
}
} // Class applicationlog
}
12. horizontal panel scrolling and vertical auto Scaling
<Asp: Panel style = "overflow-X: Scroll; overflow-Y: auto;"> </ASP: Panel>
13. Press enter to convert to Tab
<Script language = "JavaScript" for = "document" event = "onkeydown">
If (event. keycode = 13 & event. srcelement. type! = 'Button '& event. srcelement. type! = 'Submit '& event. srcelement. type! = 'Reset' & event. srcelement. type! = ''& Event. srcelement. type! = 'Textea ');
Event. keycode = 9;
</SCRIPT>
Onkeydown = "If (event. keycode = 13) event. keycode = 9"
Http://dotnet.aspx.cc/exam/enter2tab.aspx
14. DataGrid super join Column
Datanavigateurlfield = "field name" datanavigateurlformatstring = "http: // XX/INC/Delete. aspx? Id = {0 }"
15. 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 ("onmouseout", "this. style. backgroundcolor =/"" + E. item. style ["background-color"] + "/"");
E. Item. Attributes. Add ("onmouseover", "This. style. backgroundcolor =/" "+" # eff3f7 "+ "/"");
}
}
16. template Column
<Asp: templatecolumn visible = "false" sortexpression = "Demo" headertext = "ID">
<Itemtemplate>
<Asp: Label text = '<% # databinder. eval (container. dataitem, "ArticleID") %> 'runat = "server" width = "80%" id = "lblcolumn"/>
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "selected">
<Headerstyle wrap = "false" horizontalalign = "center"> <Itemtemplate>
<Asp: checkbox id = "chkexport" runat = "server"/>
</Itemtemplate>
<Edititemtemplate>
<Asp: checkbox id = "chkexporton" runat = "server" enabled = "true"/>
</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 ("chkexport ");
Chkexport. Checked = true;
}
}
Else
{
Foreach (maid in mydatagrid. Items)
{
Chkexport = (checkbox) odatagriditem. findcontrol ("chkexport ");
Chkexport. Checked = false;
}
}
}
17. digit formatting
The result of <% # container. dataitem ("price") %> is 500.0000. How to format it to 500.00 ?]
<% # Container. dataitem ("price", "{0: ¥ #,## 0.00}") %>
Int I = 123456;
String S = I. tostring ("###,##. 00 ");
18. Date formatting
[ASPX page: <% # databinder. eval (container. dataitem, "company_ureg_date") %>
Shown as: 19:44:28
I only want]
<% # Databinder. eval (container. dataitem, "company_ureg_date", "{0: yyyy-m-d}") %>
How should I change it?
[Format date]
It is usually an object.
(Datetime) objectfromdb). tostring ("yyyy-mm-dd ");
[Date verification expression]
A. The correct input format is as follows: [], [10:29:39], []
^ (/D {2} ([02468] [048]) | ([13579] [26]) [// s]? (0? [13578]) | (1 [02]) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) |
(3 [01]) | (0? [469]) | (11) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [/-// s]? (0? [1-9]) | ([1-2] [0-9])
| (/D {2} ([02468] [1235679]) | ([13579] [01345789]) [///S]? (0? [13578]) | (1 [02]) [//-// s]? (0? [1-9]) | ([1-2] [0-9])
| (3 [01]) | (0? [469]) | (11) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [/-// s]? (0? [1-9]) | (1 [0-9]) | (2 [0-8]) (/s (0? [1-9]) | (1 [0-2])/([0-5] [0-9]) (/s) | (/:( [0-5] [0-9])/s) ([am | Pm | am | PM] {2, 2 })))? $
B. The following correct input format: [0001-12-31], [9999 09 30], [2002/03/03]
^/D {4} [/-// s]? (0 [13578]) | (1 [02]) [/-///S]? ([0-2] [0-9]) | (3 [01]) | (0 [469]) | (11 )) [/-// s]? ([0-2] [0-9]) | (30) | (02 [/-///S]? [0-2] [0-9]) $
[Case-sensitive conversion]
Httputility. htmlencode (string );
Httputility. htmldecode (string)
19. How to set global variables
In global. asax
Application_start () event
Add application [attribute name] = xxx;
Is your global variable
20. How do I connect to the connection generated by hyperlinkcolumn and click Connect to open a new window?
Hyperlinkcolumn has a property target, which can be set to "_ blank" (target = "_ blank ")
[Aspnetmenu] Click the menu item to bring up a new window
Add urltarget = "_ blank" to the menu item of your menudata. xml file"
For example:
<? XML version = "1.0" encoding = "gb2312"?>
<Menudata imagesbaseurl = "images/">
<Menugroup>
<Menuitem label = "internal reference information" url = "infomation. aspx">
<Menugroup id = "BBC">
<Menuitem label = "announcement information" url = "infomation. aspx" urltarget = "_ blank" lefticon = "file.gif"/>
<Menuitem label = "" url = "newinfo. aspx" lefticon = "file.gif"/>
......
Upgrade your aspnetmenu to version 1.2.
21. Delegate Discussion
Http://community.csdn.net/Expert/topic/2651/2651579.xml? Temp =. 7183191.
Http://dev.csdn.net/develop/article/22/22951.shtm
22. Read the textbox value of the DataGrid Control.
Foreach (DataGrid DGI in yourdatagrid. Items)
{
Textbox TB = (textbox) DGI. findcontrol ("yourtextboxid ");
TB. Text ....
}
23. three template columns in the DataGrid contain textbox columns dg_shuliang (Quantity) dg_danjian (unit price) dg_jine (amount) in 5.6.7, respectively, it is required that the amount be calculated automatically when the quantity and unit price are entered: quantity * unit price = amount, and the input time limit must be numeric. how can I use a client script to implement this function?
[Si GUI 〗
<Asp: templatecolumn headertext = "quantity">
<Itemtemplate>
<Asp: textbox id = "shuliang" runat = 'server' text = '<% # databinder. eval (container. dataitem, "dg_shuliang") %>'
Onkeyup = "javascript: Docal ()"
/>
<Asp: regularexpressionvalidator id = "REVS" runat = "server" controltovalidate = "shuliang" errormessage = "must be integer" validationexpression = "^/d + $"/>
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "unit price">
<Itemtemplate>
<Asp: textbox id = "danjian" runat = 'server' text = '<% # databinder. eval (container. dataitem, "dg_danjian") %>'
Onkeyup = "javascript: Docal ()"
/>
<Asp: regularexpressionvalidator id = "revs2" runat = "server" controltovalidate = "danjian" errormessage = "must be numeric" validationexpression = "^/d + (/. /D *)? $ "/>
</Itemtemplate>
</ASP: templatecolumn>
<Asp: templatecolumn headertext = "amount">
<Itemtemplate>
<Asp: textbox id = "jine" runat = 'server' text = '<% # databinder. eval (container. dataitem, "dg_jine") %>'/>
</Itemtemplate>
</ASP: templatecolumn>
<Script language = "JavaScript">
Function Docal ()
{
VaR E = event. srcelement;
VaR ROW = E. parentnode. parentnode;
VaR txts = row. All. Tags ("input ");
If (! Txts. Length | txts. Length <3)
Return;
VaR q = txts [txts. Length-3]. value;
VaR P = txts [txts. Length-2]. value;
If (isnan (q) | isnan (p ))
Return;
Q = parseint (Q );
P = parsefloat (P );
Txts [txts. Length-1]. value = (Q * P). tofixed (2 );
}
</SCRIPT>
24. Why do I always refresh the lower row selected by the DataGrid and scroll to the top? The selected row cannot be seen due to the relationship between the screen.
Page_load
Page. smartnavigation = true
25. modify data in the DataGrid. When you click the edit key, the data appears in the text box. How to control the size of the text box?
Private void maid (OBJ sender, maid E)
{
For (INT I = 0; I <E. Item. cells. Count-1; I ++)
If (E. Item. itemtype = listitemtype. edittype)
{
E. Item. cells [I]. Attributes. Add ("width", "80px ")
}
}
26. Dialog Box
Private Static string scriptbegin = "<script language =/" javascript/"> ";
Private Static string scriptend = "</SCRIPT> ";
Public static void confirmmessagebox (string pagetarget, string content)
{
String confirmcontent = "Var retvalue = Window. confirm ('"+ content +"'); "+" If (retvalue) {window. location = '"+ pagetarget + "';}";
Confirmcontent = scriptbegin + confirmcontent + scriptend;
Page parameterpage = (PAGE) system. Web. httpcontext. Current. Handler;
Parameterpage. registerstartupscript ("Confirm", confirmcontent );
// Response. Write (strscript );
}