批量删除所有自定义的存储过程

declare   @str   varchar(8000)  
  set   @str   =   ”  
  select   @str   =   @str   +   ‘,’   +   name   From   sysobjects   WHERE   xtype=’P’   and   status>=0  
  select   @str   =   ‘drop   proc   ‘   +   substring(@str,2,8000)  
  select   @str  
  exec   (@str)   
 

datalist中ExtractTemplateRows的应用

        <asp:DataList ID="DataList1" runat="server" BorderWidth="1px" CellPadding="2"
        DataKeyField="qaa_id" DataSourceID="SqlDataSource1"  GridLines="Both" HorizontalAlign="Center" Width="98%"
        ExtractTemplateRows="True">

            <ItemTemplate>
           
            <asp:Table ID="Table1" runat="server">
                <asp:TableRow>
                    <asp:TableCell Text='<%# (Convert.ToInt32(Eval("qaa_userid"))==0)?"客服回复":"我的问题"%>’ RowSpan="2" CssClass="tdleftcol"></asp:TableCell>
                    <asp:TableCell Text='<%# Eval("qaa_content") %>’></asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>  
                    <asp:TableCell Text='<%# Eval("qaa_date") %>’ CssClass="grayfont"></asp:TableCell>              
                </asp:TableRow>
            </asp:Table>

            </ItemTemplate>
    </asp:DataList>

session失效时,再点当页,强制刷新

        private void RefreshCurrentPage()
        {
            if (Request.QueryString["randomseed"] == null)
            {
                Response.Redirect(Request.RawUrl + "?randomseed=" + DateTime.Now.ToString());
            }
        }

Request.RawUrl, 当前页网址, 加个随机种子,这样就不会再读缓存。

在detaiilview的编辑模式,自定义dropdownlist

((Label)DetailsView1.FindControl("tmpLast")).Text;

tmpLast是自定义了一个label,可以设成visible="false".来存值。

                if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
                {
                    ddlLast((DropDownList)DetailsView1.FindControl("sf_last"));
                    ((DropDownList)DetailsView1.FindControl("sf_last")).SelectedValue = ((Label)DetailsView1.FindControl("tmpLast")).Text;
                }

 

        protected void ddlLast(DropDownList myddlLast)
        {
            myddlLast.Items.Add(new ListItem("15天", "15"));
            myddlLast.Items.Add(new ListItem("30天", "30"));
            myddlLast.Items.Add(new ListItem("半年", "180"));
            myddlLast.Items.Add(new ListItem("1年", "365"));
        }

在asp.net中统计字符串A在字符串B中出现的次数

思路有多种。

  1. 正则验证匹配
  2. split分割
  3. replace替换算长度

下面以第三种方法举例

            string strReplace = "http";
            int CountHttp = ((strContent.Length – (strContent.Replace(strReplace, string.Empty)).Length)) / strReplace.Length;
 

实现的思路,想算A字符串在B字符串出现的次数.

可以用 (B字符串的长度, 去除含有的A字符串后的B字符串的长度) 除以A字符串的长度。

 

 

 

asp.net中login控件,RememberMe可能是个bug

利用vs2008中的login控件时,转成模板,后台却得不到RememberMe的值。

public partial class userlogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Login1.DestinationPageUrl = "LoginMessage.aspx";

            if (Request.IsAuthenticated == true)
            {
                Response.Redirect(Login1.DestinationPageUrl);
            }
           
           
        }

        protected void userLogin_Authenticate(object sender, AuthenticateEventArgs e)
        {
            string strUserName = Login1.UserName;
            string strPassWord = FormsAuthentication.HashPasswordForStoringInConfigFile(Login1.Password, "MD5");
            CheckBox rm = (CheckBox)Login1.FindControl("RememberMe");//估计是个微软的bug
           
            string[] ReResult = Users.ValidateUserNameAndPwd(strUserName, strPassWord);
            string ReStr = ReResult[1];

            switch (ReStr)
            {
                case "noUser":
                    e.Authenticated = false;
                    break;
                case "ErrorPWD":
                    e.Authenticated = false;
                    break;
                case "Access":
                    HttpCookie objCookie = new HttpCookie("UserInfo");
                    Response.Cookies.Remove("UserInfo");
                    objCookie.Values.Add("UserName", strUserName);
                    objCookie.Values.Add("UserPwd", strPassWord);
                    objCookie.Values.Add("UserID", ReResult[0]);
                    if (rm.Checked)
                    {
                        objCookie.Expires = DateTime.Now.AddDays(15);
                    }

                    Response.AppendCookie(objCookie);

                    e.Authenticated = true;
                    break;
            }           
             
        }

在asp.net中将detailview设为默认编辑状态

 <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
        DataKeyNames="id" DataSourceID="SqlDataSource1" Height="50px" Width="100%" 
        DefaultMode="Edit" onitemupdated="DetailsView1_ItemUpdated"
        onitemupdating="DetailsView1_ItemUpdating" >

DefaultMode="Edit" 来实现, 但你会发现,detailview不会自动回到readonly的状态了。

解决方法:onitemupdating="DetailsView1_ItemUpdating"
cs文件代码

        protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            DetailsView1.DefaultMode = DetailsViewMode.ReadOnly;
        }