快速业务通道

.NET常用功能及代码的总结与收藏

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-04-12

  双击表格打开新一页

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string OrderItemID =e.item.cells[1].Text;
...
e.item.Attributes.Add(
"ondblclick", "open(''../ShippedGrid.aspx?id=" + OrderItemID + "'')");
}

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

<asp:HyperLinkColumn Target="_blank" headertext="ID号" DataTextField="id" NavigateUrl="aaa.aspx?id=''<%# DataBinder.Eval(Container.DataItem, "数据字段1")%>'' & name=''<%# DataBinder.Eval(Container.DataItem, "数据字段2")%>'' />

  7.表格点击改变颜色

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

  写在DataGrid的_ItemDataBound里

if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add(
"onmouseover","this.style.backgroundColor=''#99cc00'';this.style.color=''buttontext'';this.style.cursor=''default'';");
e.Item.Attributes.Add(
"onmouseout","this.style.backgroundColor='''';this.style.color='''';");
}

  8.关于日期格式

  日期格式设定

DataFormatString="{0:yyyy-MM-dd}"

  我觉得应该在itembound事件中

e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd"))

  9.获取错误信息并到指定页面

e.g
// in global.asax
protected void Application_Error(Object sender, EventArgs e) {
if (Server.GetLastError() is HttpUnhandledException)
Server.Transfer(
"MyErrorPage.aspx");

  不要使用Response.Redirect,而应该使用Server.Transfer

//其余的非HttpUnhandledException异常交给ASP.NET自己处理就okay了 :)

  Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理

  10.清空Cookie

Cookie.Expires=[DateTime];
Response.Cookies(
"UserName").Expires = 0

11.自定义异常处理

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号