In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the common code in ASP.NET". In daily operation, I believe many people have doubts about the common code in ASP.NET. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt about "what is the common code in ASP.NET?" Next, please follow the editor to study!
17. Digital formatting
The result of [<% # Container.DataItem ("price")% > is 500.0000. How to format it to 500.00?]
<% # Container.DataItem ("price", "{0: ¥#, # # 0.00}")% > int iTunes 123456; string s=i.ToString ("# .00")
18. Date formatting
[within the aspx page: <% # DataBinder.Eval (Container.DataItem, "Company_Ureg_Date")% > is displayed as: 2004-8-11 19:44:28 I only want: 2004-8-11]
<% # DataBinder.Eval (Container.DataItem, "Company_Ureg_Date", "{0:yyyy-M-d}")% >
How should I change it?
[format date]
Take it out, usually object ((DateTime) objectFromDB) .ToString ("yyyy-MM-dd")
[validation expression for date]
a. The following correct input format: [2004-2-29], [2004-02-29 10:29:39 pm], [2004-12-31]
^ (\ d {2} ([02468] [048]) | ([13579] [26])) [\ -\ /\ s]? (0? [13578]) | (1 [02])) [\ -\ /\ s]? ((0? [1-9]) | ([1-2] [0-9])) | ((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]) | (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] {2pm 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 conversion]
HttpUtility.HtmlEncode (string); HttpUtility.HtmlDecode (string)
19. How to set global variables
In Global.asax
In the Application_Start () event
Add Application [attribute name] = xxx
Is your global variable.
20. How to make the connection generated by HyperLinkColumn, click the connection and 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 items in your menuData.xml file, such as:
< 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= "compile the information bulletin" URL= "NewInfo.aspx" LeftIcon= "file.gif" / >.
* upgrade your aspnetmenu to version 1.2
21. Read the DataGrid control TextBox value
Foreach (DataGrid dgi in yourDataGrid.Items) {TextBox tb = (TextBox) dgi.FindControl ("yourTextBoxId"); tb.Text.... }
twenty-two。 There are three template columns in DataGrid that contain Textbox as DG_ShuLiang (quantity) DG_DanJian (unit price) DG_JinE (amount) in 5.6.7.It is required to automatically calculate the amount when entering quantity and unit price, that is, quantity * unit price = amount is also required to be limited to numerical type. How can I do this with client script?
< 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=" ^\ dprice $"/ > < / 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 "DG_JinE")% >'/ > < / ItemTemplate > < / asp:TemplateColumn > < script language= "javascript" > function DoCal () {var e = event.srcElement Var row = e [XSS _ clean] [xss_clean]; 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 >
When 23.datagrid selects the row at the bottom of the comparison, why does it always refresh it, and then scroll to the top? the row just selected cannot be seen because of the screen.
Page_load page.smartNavigation=true
24. Modify the data in 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 DataGrid1_ItemDataBound (obj sender,DataGridItemEventArgs e) {for (int item.Cells.CountMuy1 +) if (e.Item.ItemType==ListItemType.EditType) {e.Item.Cells [I] .Attributes.add ("Width", "80px")}}
25. 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);}
twenty-six。 Format time: string aa=DateTime.Now.ToString ("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
1.1 take the current year, month, day, hour, minute and second
CurrentTime=System.DateTime.Now
1.2 take the current year
Int year = DateTime.Now.Year
1.3 take the current month
Int month = DateTime.Now.Month
1.4 take the current day
Int day = DateTime.Now.Day
1.5 take the current tense
Int = DateTime.Now.Hour
1.6 take the current score
Int score = DateTime.Now.Minute
1.7 take the current second
Int seconds = DateTime.Now.Second
1.8 take the current millisecond
Int milliseconds = DateTime.Now.Millisecond
27. Custom paging code:
Define variables first:
Public static int pageCount; / / Total pages public static int curPageIndex=1; / / current page
Next page:
If (DataGrid1.CurrentPageIndex < (DataGrid1.PageCount-1)) {DataGrid1.CurrentPageIndex + = 1; curPageIndex+=1;} bind (); / / DataGrid1 data binding function previous page: if (DataGrid1.CurrentPageIndex > 0) {DataGrid1.CurrentPageIndex + = 1; curPageIndex-=1;} bind (); / / DataGrid1 data binding function direct page jump: int a=int.Parse (JumpPage.Value.Trim ()) / / JumpPage.Value.Trim () is the jump value if (a < DataGrid1.PageCount) {this.DataGrid1.CurrentPageIndex=a;} bind ()
28.DataGrid uses:
Adding deletion confirmation is also a common ASP.NET code:
Private void DataGrid1_ItemCreated (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {foreach (DataGridItem di in this.DataGrid1.Items) {if (di.ItemType==ListItemType.Item | | di.ItemType==ListItemType.AlternatingItem) {((LinkButton) di.Cells [8] .controls [0]) .Attributes.Add ("onclick", "return confirm ('confirm to delete this item?');}
Alternating styles:
ListItemType itemType = e.Item.ItemType; if (itemType = = ListItemType.Item) {e.Item.Attributes ["onmouseout"] = "_ javascript:this.style.backgroundColor='#FFFFFF';"; e.Item.Attributes ["onmouseover"] = "_ javascript:this.style.backgroundColor='#d9ece1';cursor='hand';" } else if (itemType = = ListItemType.AlternatingItem) {e.Item.Attributes ["onmouseout"] = "_ javascript:this.style.backgroundColor='#a0d7c4';"; e.Item.Attributes ["onmouseover"] = "_ javascript:this.style.backgroundColor='#d9ece1';cursor='hand';";}
Add a numbered column:
DataTable dt= c.ExecuteRtnTableForAccess (sqltxt); / / execute the DataTable DataColumn dc=dt.Columns.Add returned by sql ("number", System.Type.GetType ("System.String")); for (int iFixt I < dt.Rows.Count;i++) {dt.Rows [I] ["number"] = (iTun1). ToString ();} DataGrid1.DataSource=dt; DataGrid1.DataBind ()
Add a CheckBox to the DataGrid1 and a full check box to the page
Private void CheckBox2_CheckedChanged (object sender, System.EventArgs e) {foreach (DataGridItem thisitem in DataGrid1.Items) {((CheckBox) thisitem.Cells [0] .controls [1]) .checked = CheckBox2.Checked;}}
Delete all the data displayed by DataGrid1 in the current page
Foreach (DataGridItem thisitem in DataGrid1.Items) {if (CheckBox) thisitem.Cells [0] .controls [1]) .checked) {string strloginid= DataGrid 1.DataKeys [thisitem.ItemIndex] .ToString (); Del (strloginid); / / delete function}}
29. When the file is in a different directory, you need to get the database connection string (if the connection string is placed in Web.config, then initialize it in Global.asax)
Add the following code to Application_Start:
Application ["ConnStr"] = this.Context.Request.PhysicalApplicationPath+ConfigurationSettings. AppSettings ["ConnStr"] .ToString ()
30. Variable .ToString ()
Character conversion to string
12345.ToString ("n"); / / generate 12345.00
12345.ToString ("C"); / / generate ¥12345.00
12345.ToString ("e"); / / generate 1.234500e+004
12345.ToString ("f4"); / / generate 12345.0000
12345.ToString ("x"); / / generate 3039 (hexadecimal)
12345.ToString ("p"); / / generate 1234500.00%
thirty-one。 Variable .Substring (parameter 1, parameter 2)
To intercept part of a string, parameter 1 is the starting bit from the left, and parameter 2 is the number of digits to be intercepted. For example, string S1 = str.Substring (0penny 2)
32. Log in to other sites on your own website: (if your page is nested, because there can only be one FORM on one page, you can go to another page and submit login information.)
< SCRIPT language= "javascript" > < / SCRIPT > < body leftMargin= "0" topMargin= "0" onload=_javascript:gook () "marginwidth=" 0 "marginheight=" 0 "> < form name=" frm "action=" http://220.194.55.68:6080/login.php?retid=7259 "method=" post "> < tr > < td > < input id=" f_user "type=" hidden "size=" 1 "name=" f_user "runat=" server "> < input id= "f_domain" type= "hidden" size= "1" name= "f_domain" runat= "server" > < input class= "box" id= "f_pass" type= "hidden" size= "1" name= "pwshow" runat= "server" > < INPUT id= "lng" type= "hidden maxLength=" 20 "size=" 1 "value=" 5 "name=" lng "> < INPUT id=" tem "type=" hidden "size=" 1 "value=" 2 "name=" tem "> < / Td > < / tr > < / form >
The name of the text box must be the name of the page you want to log in to. If the source code does not work, you can use vsniffer to see it.
Here is the code to get the login information entered by the user:
String name; name=Request.QueryString ["EmailName"]; try {int a=name.IndexOf ("@", 0memename. Length); f_user.Value=name.Substring (0meme a); f_domain.Value=name.Substring (axi1Lame.length); f_pass.Value=Request.QueryString ["Psw"];} catch {Script.Alert ("wrong mailbox!") Server.Transfer ("index.aspx"); at this point, the study on "what is the common code in ASP.NET" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.