[ASP.NET]工作中经常使用到的方法

 1、给删除按钮添加是否确认提示:
   前台方法:OnClientClick="return window.confirm('你确定要删除吗?')"
   后台方法:btnDelete.Attributes.Add("onclick", "return confirm('您确定要删除吗?');");
2、DataSet中取值:
   lblTitle.Text = ds.Tables[0].Rows[0]["Title"].ToString();
   
3、字符串截取方法:
   public string StringFormat(int len, string str)
   {
      return (str.Length > len) ? str.Substring(0, len) + " ..." : str;
   }
4、GridView事件中获取GridView中的控件:
   LinkButton lbtnManager = e.Row.FindControl("lbtnManager") as LinkButton;
   
5、获取GridView的DataKeyNames中主键的ID值:
  int id = Convert.ToInt32((sender as GridView).DataKeys[e.Row.RowIndex].Value.ToString());
6、ViewState的应用:
   [网站前台,尽量禁用ViewState;当然也最好不要使用PostBack]
        public string vsEName
    {
        get
        {
            if (EnableViewState)
            {
                object obj = ViewState["eName"];
                if (obj != null)
                    return (string)obj;
                else
                    return string.Empty;
            }
            else
                return string.Empty;
        }
        set
 

你可能感兴趣的:([ASP.NET]工作中经常使用到的方法)