重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

asp.net在动态网页中的使用技巧

站在用户的角度思考问题,与客户深入沟通,找到融水网站设计与融水网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都做网站、网站建设、外贸营销网站建设、企业官网、英文网站、手机端网站、网站推广、主机域名、虚拟空间、企业邮箱。业务覆盖融水地区。

1.为按钮添加确认对话框

Button.Attributes.Add(" confirm('确认?')");

Button.Attributes.Add("onclick","if(confirm('确定?')){return true;}else{return false;}")

 

2.表格超连接列传递参数

'&name='<%# DataBinder.Eval(Container.DataItem, "数据字段2")%>'/>

 

3.表格点击改变颜色

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';");

}

 

4.清空Cookie

Cookie.Expires=[DateTime];

Response.Cookies("UserName").Expires = 0;

 

5.Panel横向滚动,纵向自动扩展

 

6.数字格式化

<%#Container.DataItem("price")%>结果:500.0000格式化:500.00

<%#Container.DataItem("price","{0:¥#,##0.00}")%>

int i=123456;

string s=i.ToString("###,###.00");

 

7.日期格式化

<%# DataBinder.Eval(Container.DataItem,"Date")%>结果:2004-8-11 19:44:28格式化:2004-8-11

<%# DataBinder.Eval(Container.DataItem,"Date","{0:yyyy-M-d}")%>

 

8.时间格式化

string aa=DateTime.Now.ToString("yyyy年MM月dd日");

当前年月日时分秒 currentTime=System.DateTime.Now;

当前年 int年= DateTime.Now.Year;

当前毫秒 int毫秒= DateTime.Now.Millisecond;

 

9.自定义分页代码

public static int pageCount; //总页面数

public static int curPageIndex=1; //当前页面  

if(ccDataGrid.CurrentPageIndex<(ccDataGrid.PageCount - 1))

{//下一页

ccDataGrid.CurrentPageIndex += 1;

curPageIndex+=1;

}

bind(); // ccDataGrid数据绑定函数

if(ccDataGrid.CurrentPageIndex>0)

{ //上一页

ccDataGrid.CurrentPageIndex += 1;

curPageIndex-=1;

}

bind(); // ccDataGrid数据绑定函数

int a=int.Parse(JumpPage.Value.Trim());//JumpPage.Value.Trim()为跳转值

if(a

{ //直接页面跳转

this.ccDataGrid.CurrentPageIndex=a;

}

bind(); // ccDataGrid数据绑定函数

 

10.变量.ToString()

字符型转换 转为字符串

12345.ToString("n"); //生成 12,345.00

12345.ToString("C"); //生成 ¥12,345.00

12345.ToString("e"); //生成 1.234500e+004

12345.ToString("f4"); //生成 12345.0000

12345.ToString("x"); //生成 3039 (16进制)

12345.ToString("p"); //生成 1,234,500.00%

 

11.客户端验证控件

//验证空值

//验证网址

//验证邮箱

//验证邮编

//显示错误信息

 

12.DataBinding绑定表达式

以该oil paintings网站案例来说,它的产品页面都调用了DataBinding绑定表达式

1)普通的绑定表达式

<%# DataBinder.Eval(Container.DataItem, "ContactName") %>

2)文本+绑定表达式

3)同时带有显示格式的绑定表达式

<%# DataBinder.Eval(Container,"DataItem.USActiveDate","{0:yyyy-MM-dd}") %>

4)结合绑定表达式和模态框

其中:后台代码文件中ShowModalWin()方法的定义如下:

protected string ShowModalWin(string PictureImage,string DetailID,string PictureID)

{

return " window.showModalDialog(\"Customers/ShowPictureInfo.aspx?pid="+PictureImage+"&did="+DetailID+"&id="+PictureID+"\",\"\",\"dialogHeight:320px;dialogWidth:480px;center:yes;help:no;status:no;scroll:no\");";

}

或者将参数提取出来单独定义成一变量:

const string WINDOWPARAMSTRING="dialogWidth:540px;dialogHeight:420px;help:0;status:0;resizeable:1;scroll:no";

Page.RegisterStartupScript("functionscript","");

 

13.html字符转换的两个函数

public string Encode(string str)

{

str=str.Replace("&","&");

str=str.Replace("'","''");

str=str.Replace("\"",""");

str=str.Replace(" "," ");

str=str.Replace("<","<");

str=str.Replace(">",">");

str=str.Replace("\n","
");

return str;

}

public string Decode(string str)

{

str=str.Replace("\n","
");

str=str.Replace(">",">");

str=str.Replace("<","<");

str=str.Replace(" "," ");

str=str.Replace(""","\"");

return str;

}


网站题目:asp.net在动态网页中的使用技巧
链接URL:
http://cqcxhl.com/article/gdsdpj.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP