我丢块砖,大家来砸玉吧:
==================
子窗体返回主窗体  ///<summary> 
 ///名称:redirect 
 ///功能:子窗体返回主窗体 
 ///参数:url 
 ///返回值:空 
 ///</summary> 
 public void redirect(string url,Page page) 
 { 
  if ( Session["IfDefault"]!=(object)"Default") 
  {     
   page.RegisterStartupScript("","<script>window.top.document.location.href='"+url+"';</script>"); 
  } 
 }  判断是否为数字  /// <summary> 
 /// 名称:IsNumberic 
 /// 功能:判断输入的是否是数字 
 /// 参数:string oText:源文本 
 /// 返回值: bool true:是 false:否 
 /// </summary> 
  
 public bool IsNumberic(string oText) 
 { 
  try 
  { 
   int var1=Convert.ToInt32 (oText); 
   return true; 
  } 
  catch 
  { 
   return false; 
  } 
 }  获得字符串实际长度(包括中文字符)  //获得字符串oString的实际长度 
 public int StringLength(string oString) 
 { 
  byte[] strArray=System.Text .Encoding.Default .GetBytes (oString); 
  int res=strArray.Length ; 
  return res; 
 }  将回车转换为TAB  //当在有keydown事件的控件上敲回车时,变为tab 
 public void Tab(System.Web .UI.WebControls .WebControl webcontrol) 
 { 
  webcontrol.Attributes .Add ("onkeydown", "if(event.keyCode==13) event.keyCode=9"); 
 }  datagrid分页中如果删除时出现超出索引  public void jumppage(System.Web.UI.WebControls.DataGrid dg) 
 { 
  int int_PageLess; //定义页面跳转的页数 
  //如果当前页是最后一页 
  if(dg.CurrentPageIndex == dg.PageCount-1) 
  { 
   //如果就只有一页 
   if(dg.CurrentPageIndex == 0) 
   { 
    //删除后页面停在当前页 
    dg.CurrentPageIndex = dg.PageCount-1;    
   } 
   else 
   { 
    //如果最后一页只有一条记录 
    if((dg.Items.Count % dg.PageSize == 1) || dg.PageSize == 1) 
    { 
     //把最后一页最后一条记录删除后,页面应跳转到前一页 
     int_PageLess = 2; 
    } 
    else      //如果最后一页的记录数大于1,那么在最后一页删除记录后仍然停在当前页 
    { 
     int_PageLess = 1; 
    } 
    dg.CurrentPageIndex = dg.PageCount - int_PageLess; 
   } 
  } 
 }

解决方案 »

  1.   

    判断是否为数字的方法,记得CSDN上有篇文章,专门讲哪个速度快,呵。
    记得结果是逐个判断最快
      

  2.   

    更新地址中的变量的方法,当你要在一个叶面中实现不同功能,又想防止用户从新刷新的时候很有用。public static void UpdateQuery(NameValueCollection queryString, string key, string keyValue, bool isEncodeValue)
    {
    if ( isEncodeValue ) keyValue = HttpUtility.UrlEncode(keyValue); if (queryString[key]==null )
    {
    // new key, add it
    queryString.Add(key, keyValue);
    }
    else
    {
    // key exist, update the value
    queryString.Set(key, keyValue);
    }
    }
      

  3.   

    将querystirng转换成url:
    public static string GetRedirectUrl(NameValueCollection queryString)
    {
    string redirectUrl = string.Empty;
    int counter = 0;
    foreach(string key in queryString.Keys)
    {
    redirectUrl += string.Format("{0}{1}={2}", (counter>0)?"&":"", key, queryString[key]);
    counter++;
    }
    return redirectUrl;
    }
      

  4.   

    Asp.net中DataGrid控件的自定义分页
    http://blog.csdn.net/zhzuo/archive/2004/10/28/156647.aspx
    asp.net中显示DataGrid控件列序号的几种方法
    http://blog.csdn.net/zhzuo/archive/2004/09/10/100882.aspx
      

  5.   

    Base64编码
    public string EncodeBase64(string code_type,string code)
      {
       string encode = "";
       byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code);
       try
       {
        encode = Convert.ToBase64String(bytes);
       }
       catch
       {
        encode = code;
       }
       return encode;
      }
    Base64解码
    public string DecodeBase64(string code_type,string code)
      {
       string decode = "";
       byte[] bytes = Convert.FromBase64String(code);
       try
       {
        decode = Encoding.GetEncoding(code_type).GetString(bytes);
       }
       catch
       {
        decode = code;
       }
       return decode;
      }
      

  6.   

    著名的singleton 模式。也就是,一个类永远只有一个对象
    保证一个类仅有一个实例,并提供一个访问它的全局访问点。
    适用性:
    当类只能有一个实例而且客户可以从一个众所周知的访问点访问它时。 
    当这个唯一实例应该是通过子类化可扩展的,并且客户应该无需更改代码就能使用一个扩展的实例时。 namespace Singleton_DesignPattern
    {
        using System; class Singleton 
    {
    private static Singleton _instance;

    public static Singleton Instance()
    {
    if (_instance == null)
    _instance = new Singleton();
    return _instance;
    }
    protected Singleton(){} // Just to prove only a single instance exists
    private int x = 0;
    public void SetX(int newVal) {x = newVal;}
    public int GetX(){return x;}
    }    /// <summary>
        ///    Summary description for Client.
        /// </summary>
        public class Client
        {
            public static int Main(string[] args)
            {
                int val;
    // can't call new, because constructor is protected
    Singleton FirstSingleton = Singleton.Instance(); 
    Singleton SecondSingleton = Singleton.Instance(); // Now we have two variables, but both should refer to the same object
    // Let's prove this, by setting a value using one variable, and 
    // (hopefully!) retrieving the same value using the second variable
    FirstSingleton.SetX(4);
    Console.WriteLine("Using first variable for singleton, set x to 4"); val = SecondSingleton.GetX();
    Console.WriteLine("Using second variable for singleton, value retrieved = {0}", val);
                return 0;
            }
        }
    }
      

  7.   

    ccat(智拙) 共享一下怎么样?[email protected]
      

  8.   

    不如都留下blog
    我的:cuijiazhao.mblogger.cn
      

  9.   

    我的Blog是http://blog.csdn.net/ccat