ASP.NET常用的三十三種實用代碼(2)_.Net教程
推薦:新手入門之ASP.NET2.0中的緩存技術(shù)解析ASP.NET2.0提供如下緩存方式: Output Caching Fragment Caching Data Cache SQL Cache Cache Configuration 1. Output Caching: 當一個網(wǎng)頁被頻繁訪問時,我們可以把把整
| 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.關(guān)于日期格式
日期格式設(shè)定
| DataFormatString="{0:yyyy-MM-dd}" |
我覺得應(yīng)該在itembound事件中
| e.items.cell["你的列"].text=DateTime.Parse(e.items.cell["你的列"].text.ToString("yyyy-MM-dd")) |
9.獲取錯誤信息并到指定頁面
不要使用Response.Redirect,而應(yīng)該使用Server.Transfer
e.g
|
// in global.asax //其余的非HttpUnhandledException異常交給ASP.NET自己處理就okay了 :) |
Redirect會導(dǎo)致post-back的產(chǎn)生從而丟失了錯誤信息,所以頁面導(dǎo)向應(yīng)該直接在服務(wù)器端執(zhí)行,這樣就可以在錯誤處理頁面得到出錯信息并進行相應(yīng)的處理
10.清空Cookie
| Cookie.Expires=[DateTime]; Response.Cookies("UserName").Expires = 0 |
11.自定義異常處理
分享:用 asp.net 動態(tài)設(shè)置 WebService 引用有時候需要動態(tài)的設(shè)置 WebService 的址,這樣發(fā)布到不同的服務(wù)器時就要重新生成,為此我們需要在web.config中動態(tài)配置WebService的地址,在網(wǎng)上查了很多資料,其中這種方法感覺很好用也很好實現(xiàn)
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實例(可帶附件)
- js實現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進度條的實現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實現(xiàn)分頁示例代碼
- 相關(guān)鏈接:
- 教程說明:
.Net教程-ASP.NET常用的三十三種實用代碼(2)
。