ASP. NET Common collection code 4

Source: Internet
Author: User

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]) | ([2, 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.

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>

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....
}

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.