Thirteen common codes in ASP. NET programs [4]

Source: Internet
Author: User
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 the 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. Read the textbox value of the DataGrid Control

foreach(DataGrid dgi in yourDataGrid.Items)
{
 TextBox tb = (TextBox)dgi.FindControl("yourTextBoxId");
 tb.Text....
}

  23. there are three template columns in the DataGrid that contain textbox: dg_shuliang (Quantity) dg_danjian (unit price) dg_jine (amount) in the 5.6.7 column respectively. The amount must be calculated automatically when the number and unit price are entered.: Quantity * unit price = The amount also requires that the input time limit be set to numeric. How can I use client scripts 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>

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.