ImageVerifierCode 换一换
格式:DOCX , 页数:25 ,大小:25.79KB ,
资源ID:4957638      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4957638.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Aspnet开发必备51种代码非常实用.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Aspnet开发必备51种代码非常实用.docx

1、Aspnet开发必备51种代码非常实用1./弹出对话框.点击转向指定页面 Response.Write(window.alert(该会员没有提交申请,请重新提交!);Response.Write(window.location =/upmeb.aspx);2./弹出对话框Response.Write(alert(产品添加成功!);3./删除文件string filename =157517.jpg;./file/)+filename);4./绑定下拉列表框datalist dv=conn.Exec_ex(select -1 as code,请选择经营模式 as content from dea

2、lin union select code,content from dealin);content;code; ;dealincode.ToString().Selected=true;5./时间去秒显示6./标题带链接%# + DataBinder.Eval(Container.DataItem,proname)+%7./修改转向%# +修改+%8./弹出确定按钮%# +删除+%9./输出数据格式化 0:F2 是格式 F2表示小数点后剩两位10./提取动态网页内容Uri uri = new Uri(); WebRequest req = WebRequest.Create(uri); We

3、bResponse resp = req.GetResponse(); Stream str = resp.GetResponseStream(); StreamReader sr = new StreamReader(str,; string t = sr.ReadToEnd(); ;11./获取 . 后面的字符i.ToString().Trim().Substring(i.ToString().Trim().LastIndexOf(.)+1).ToLower().Trim()12. 打开新的窗口并传送参数: 传送参数:response.write(scriptwindow.open(*.a

4、spx?id=+&id1=+.+)/script)接收参数:string a = Request.QueryString(id);string b = Request.QueryString(id1);12.为按钮添加对话框onclick,return confirm(确认?);onclick,if(confirm(are you sure.?)return true;elsereturn false;)13.删除表格选定记录int intEmpID = (int)MyDataGrid.DataKeys;string deleteCmd = Delete from Employee where

5、 emp_id = + intEmpID.ToString()14.删除表格记录警告private void DataGrid_ItemCreated(Object sender,DataGridItemEventArgs e)switch(case ListItemType.Item :case ListItemType.AlternatingItem :case ListItemType.EditItem:TableCell myTableCell;myTableCell = ;LinkButton myDeleteButton ;myDeleteButton = (LinkButton)

6、myTableCell.Controls0;onclick,return confirm(您是否确定要删除这条信息););break;default:break;15.点击表格行链接另一页private void grdCustomer_ItemDataBound(object sender, e)/点击表格打开if ( = ListItemType.Item | = ListItemType.AlternatingItem)onclick,window.open(Default.aspx?id= + + ););双击表格连接到另一页在itemDataBind事件中if( = ListItem

7、Type.Item | = ListItemType.AlternatingItem)string orderItemID =;ondblclick, location.href=./ShippedGrid.aspx?id= + orderItemID + );双击表格打开新一页if( = ListItemType.Item | = ListItemType.AlternatingItem)string orderItemID =;ondblclick, open(./ShippedGrid.aspx?id= + orderItemID + );16.表格超连接列传递参数asp:HyperLi

8、nkColumn Target=_blank headertext=ID号 DataTextField=id NavigateUrl=aaa.aspx?id=%# DataBinder.Eval(Container.DataItem, 数据字段1)% & name=%# DataBinder.Eval(Container.DataItem, 数据字段2)% /17.表格点击改变颜色if ( = ListItemType.Item | = ListItemType.AlternatingItem)onclick,; ;); 写在DataGrid的_ItemDataBound里if ( = Lis

9、tItemType.Item | = ListItemType.AlternatingItem)onmouseover,;);onmouseout,;);18.关于日期格式日期格式设定DataFormatString=0:yyyy-MM-dd我觉得应该在itembound事件中你的列.text=DateTime.Parse(你的列.text.ToString(yyyy-MM-dd)19.获取错误信息并到指定页面不要使用Response.Redirect,而应该使用Server.Transfere.g/ in global.asaxprotected void Application_Error

10、(Object sender, EventArgs e) if (Server.GetLastError() is HttpUnhandledException)Server.Transfer(MyErrorPage.aspx);/其余的非HttpUnhandledException异常交给ASP.NET自己处理就okay了 :)Redirect会导致postback的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理 20.清空CookieCookie.Expires=DateTime;Response.Cookies(UserN

11、ame).Expires = 021.自定义异常处理/自定义异常处理类 using System;using System.Diagnostics;namespace MyAppException/ summary/ 从系统异常类ApplicationException继承的应用程序异常处理类。/ 自动将异常内容记录到Windows NT/2000的应用程序日志/ /summarypublic class AppException:System.ApplicationExceptionpublic AppException()if (ApplicationConfiguration.Event

12、LogEnabled)LogEvent(出现一个未知错误。);public AppException(string message)LogEvent(message);public AppException(string message,Exception innerException)LogEvent(message);if (innerException != null)LogEvent(innerException.Message);/日志记录类using System;using System.Configuration;using System.Diagnostics;using S

13、ystem.IO;using System.Text;using System.Threading;namespace MyEventLog/ summary/ 事件日志记录类,提供事件日志记录支持 / remarks/ 定义了4个日志记录方法 (error, warning, info, trace) / /remarks/ /summarypublic class ApplicationLog/ summary/ 将错误信息记录到Win2000/NT事件日志中/ param name=message需要记录的文本信息/param/ /summarypublic static void Wr

14、iteError(String message)WriteLog(TraceLevel.Error, message);/ summary/ 将警告信息记录到Win2000/NT事件日志中/ param name=message需要记录的文本信息/param/ /summarypublic static void WriteWarning(String message)WriteLog(TraceLevel.Warning, message);/ summary/ 将提示信息记录到Win2000/NT事件日志中/ param name=message需要记录的文本信息/param/ /summ

15、arypublic static void WriteInfo(String message)WriteLog(TraceLevel.Info, message);/ summary/ 将跟踪信息记录到Win2000/NT事件日志中/ param name=message需要记录的文本信息/param/ /summarypublic static void WriteTrace(String message)WriteLog(TraceLevel.Verbose, message);/ summary/ 格式化记录到事件日志的文本信息格式/ param name=ex需要格式化的异常对象/pa

16、ram/ param name=catchInfo异常信息标题字符串./param/ retvalue/ para格式后的异常信息字符串,包括异常内容和跟踪堆栈./para/ /retvalue/ /summarypublic static String FormatException(Exception ex, String catchInfo)StringBuilder strBuilder = new StringBuilder();if (catchInfo != String.Empty)strBuilder.Append(catchInfo).Append(rn);strBuild

17、er.Append(ex.Message).Append(rn).Append(ex.StackTrace);return strBuilder.ToString();/ summary/ 实际事件日志写入方法/ param name=level要记录信息的级别(error,warning,info,trace)./param/ param name=messageText要记录的文本./param/ /summaryprivate static void WriteLog(TraceLevel level, String messageText)try EventLogEntryType L

18、ogEntryType;switch (level)case TraceLevel.Error:LogEntryType = EventLogEntryType.Error;break;case TraceLevel.Warning:LogEntryType = EventLogEntryType.Warning;break;case TraceLevel.Info:LogEntryType = EventLogEntryType.Information;break;case TraceLevel.Verbose:LogEntryType = EventLogEntryType.Success

19、Audit;break;default:LogEntryType = EventLogEntryType.SuccessAudit;break;EventLog eventLog = new EventLog(Application, ApplicationConfiguration.EventLogMachineName, ApplicationConfiguration.EventLogSourceName );/写入事件日志eventLog.WriteEntry(messageText, LogEntryType);catch /忽略任何异常 /class ApplicationLog2

20、2.Panel 横向滚动,纵向自动扩展asp:panel style=overflow-x:scroll;overflow-y:auto;/asp:panel23.回车转换成Tab (1)script language=javascript for=document event=onkeydownif(event.keyCode=13 & & & & ; event.keyCode=9;/script(2) /当在有keydown事件的控件上敲回车时,变为tabpublic void Tab(System.Web .UI.WebControls .WebControl webcontrol)

21、webcontrol.Attributes .Add (onkeydown, if(event.keyCode=13) event.keyCode=9); 24.DataGrid超级连接列DataNavigateUrlField=字段名 DataNavigateUrlFormatString=25.DataGrid行随鼠标变色private void DGzf_ItemDataBound(object sender, e)if ( onmouseout,+BACKGROUND-COLOR+); onmouseover,+ #EFF3F7+);26.模板列ASP:TEMPLATECOLUMN v

22、isible=False sortexpression=demo headertext=IDITEMTEMPLATEASP LABEL text=%# DataBinder.Eval(Container.DataItem, ArticleID)% runat=server width=80% id=lblColumn /ITEMTEMPLATE/ASP:TEMPLATECOLUMNASP:TEMPLATECOLUMN headertext=选中HEADERSTYLE wrap=False horiz/HEADERSTYLEITEMTEMPLATEASP:CHECKBOX id=chkExpor

23、t runat=server /ITEMTEMPLATEEDITITEMTEMPLATEASP:CHECKBOX id=chkExportON runat=server enabled=true /EDITITEMTEMPLATE/ASP:TEMPLATECOLUMN后台代码protected void CheckAll_CheckedChanged(object sender, System.EventArgs e)/改变列的选定,实现全选或全不选。CheckBox chkExport ;if( CheckAll.Checked)foreach(DataGridItem oDataGridI

24、tem in MyDataGrid.Items)chkExport = (CheckBox)oDataGridItem.FindControl(chkExport);chkExport.Checked = true;elseforeach(DataGridItem oDataGridItem in MyDataGrid.Items)chkExport = (CheckBox)oDataGridItem.FindControl(chkExport);chkExport.Checked = false;27.数字格式化【%#Container.DataItem(price)%的结果是500.000

25、0,怎样格式化为500.00?】%#Container.DataItem(price,0:¥#,#0.00)%int i=123456;string s=i.ToString(#,#.00);28.日期格式化【aspx页面内:%# DataBinder.Eval(Container.DataItem,Company_Ureg_Date)%显示为: 2004-8-11 19:44:28我只想要:2004-8-11 】%# DataBinder.Eval(Container.DataItem,Company_Ureg_Date,0:yyyy-M-d)%应该如何改?【格式化日期】取出来,一般是object(DateTime)objectFromDB).ToString(yyyy-MM-dd);【日期的验证表达式】A.以下正确的输入格式: 2004-2-29, 2004-02-29 10:29:39 pm, 2004/12/31 (d2(02468048)|(1357926)-/s?(0?13578)|(102)-/s?(0?1-9)|(1-20-9)|(301)|(0?469)|(11)-/s?(0?1-9)|(1-20-9)|(30)|(0?2

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1