Posted by & filed under ASP.NET.

リンク: ASP.NET程序中常用代码汇总(四)  – dotnet.csdn.net 团队blog (测试).
31. 当文件在不同目录下,需要获取数据库连接字符串(如果连接字符串放在Web.config,然后在Global.asax中初始化)
在Application_Start中添加以下代码:

Application[“ConnStr“]=this.Context.Request.PhysicalApplicationPath+ConfigurationSettings.
   AppSettings[“ConnStr“].ToString();

32.变量.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%

33.变量.Substring(参数1,参数2);
截取字串的一部分,参数1为左起始位数,参数2为截取几位。 如:string s1 = str.Substring(0,2);

Posted by & filed under ASP.NET.

リンク: ASP.NET程序中常用代码汇总(三)  – dotnet.csdn.net 团队blog (测试).
31. 当文件在不同目录下,需要获取数据库连接字符串(如果连接字符串放在Web.config,然后在Global.asax中初始化)
在Application_Start中添加以下代码:

Application[“ConnStr“]=this.Context.Request.PhysicalApplicationPath+ConfigurationSettings.
   AppSettings[“ConnStr“].ToString();

32.变量.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%

33.变量.Substring(参数1,参数2);
截取字串的一部分,参数1为左起始位数,参数2为截取几位。 如:string s1 = str.Substring(0,2);

Posted by & filed under ASP.NET.

11.自定义异常处理

//自定义异常处理类
using System;
using System.Diagnostics;

namespace MyAppException
{
 /**//// <summary>
 /// 从系统异常类ApplicationException继承的应用程序异常处理类。
 /// 自动将异常内容记录到Windows NT/2000的应用程序日志
 /// </summary>
 public class AppException:System.ApplicationException
 {
  public AppException()
  {
   if (ApplicationConfiguration.EventLogEnabled)LogEvent(“出现一个未知错误。“);
  }

 public AppException(string message)
 {
  LogEvent(message);
 }

 public AppException(string message,Exception innerException)
 {
  LogEvent(message);
  if

Posted by & filed under ASP.NET.

リンク: ASP.NET程序中常用代码汇总(一)  – dotnet.csdn.net 团队blog (测试).
1. 打开新的窗口并传送参数:

//传送参数:
response.write(“<script>window.open(’*.aspx?id=“+this.DropDownList1.SelectIndex+“&id1=“++“’)</script>“)
  //接收参数:
string a = Request.QueryString(“id“);
string b = Request.QueryString(“id1“);

2.为按钮添加对话框

Button1.Attributes.Add(“onclick“,“return confirm(’确认?’)“);
button.attributes.add(“onclick“,“if(confirm(’are you sure?’)){return true;}else{return false;}“)

3.删除表格选定记录

int intEmpID = (int)MyDataGrid.DataKeys[e.Item.ItemIndex];
string deleteCmd = “DELETE from Employee