工作小结(一)--小知识点
来广卓上班也有一个月了,在这个月里面,我学会了好多东西,也许对别人来说,那些东西都是最简单的,可我之前都不会。把自己当傻瓜,你才能学到更多的东西。不管以后的路有多难,我都会一路笑着走下去。在这段时间里,不光有同事的帮助,他也在默默地支持着我,除了照顾我的饮食之外,还在工作在帮助我。这周真的很累,工作有点难,加上又感冒了,但我还是坚强地面对。
1.GridView输入英文字符或数字时,它自己是不会换行,此时就要在Page_Load中手写代码让它转行。
this.FSLGridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
2.sql中DateTime类型字段,现在只要求获取它的日期,不需要后面的时间(时分秒)。
三种格式:
select convert(char(10),getDate(),120) --yyyy-MM-dd 2009-03-15 15:10:02
select convert(char(10),getDate(),112) --yyyyMMdd 20090315
select convert(char(10),getDate(),111) --yyyy/MM/dd 2009/03/15
select convert(char(10),getDate(),105) --dd-MM-yyyy 15-03-2009
select CONVERT(varchar(12) , getdate(), 102) --2009.03.15
3.IP地址验证:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{ //验证输入的IP地址是否正确
string pattern = @"^(0|[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.(0|[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.(0|[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.(0|[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";
string strIP = this.txtServerMgIP.Text.Trim();
if (strIP != null && strIP != "")
{
if (!System.Text.RegularExpressions.Regex.IsMatch(strIP, pattern))
args.IsValid = false;
}
}
注:使用些验证控件时,不需要在前台设置ControlToValidate,只需要设置ErrorMessage。如:
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="请检查IP地址"
onservervalidate="CustomValidator1_ServerValidate">!</asp:CustomValidator>
4.javascript 身份证、军人证正则引出的问题?
今天做表单验证,碰到了身份证、军人证的验证,本以为很简单,就写了如下正则:
var identityCard = /\d{15}|\d{18}/;
var armyCard = /\d{7}/;
可惜不对,正确的如下:
var identityCard = /^(\d{15}|\d{18})$/;
var armyCard = /^\d{7}$/;
只有加了“^”和“$”才能保证只有固定的 N 位,少一位多一位都是不行的,大家可以试试!!!
5.分隔字符串:string[] serverSWName = this.txtServerSWName.Text.Trim().Split("\r\n".ToCharArray());
6.实用的html跳转
<body>
<select id="Select1" name="D1" onchange="javascript:void(location.href=this.options[this.options.selectedIndex].value)"
class="DropDownList" style="height: 20px; width: 137px">
<option value=http://mc.sgs.iap.gmcc.net/">运维中心</option>
<option value="http://iap.sgs.gd.iap">/门户首页</option>
<option value=http://dc.sgs.gd.iap/">开发中心</option>
<option value=http://rc.sgs.gd.iap/">需求中心</option>
<option value=http://tc.sgs.gd.iap/">测试中心</option>
</ select>
</body>
7.GirdView各事件执行顺序:
FSLGridView1_DataBinding
FSLGridView1_RowCreated
执行前台页面的绑定
FSLGridView1_RowDataBounding
FSLGridView1_RowDataBound