ASP.NET中常用方法总结

24 篇文章 1 订阅
15 篇文章 0 订阅

一:JQuery实现在GridView中 点击一行的任意位置  选中这一行中的CheckBox

$(function(){
        $("#GridView1").find("tr").click(function(){
            $(this).find("input[type='checkbox']").attr("checked",!$(this).find("input[type='checkbox']").attr("checked"));
             
        });
         
    })

二:在ASP.NET后台实现 GridView 光棒效果


protected void gvProjectList_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
	//这是鼠标移到某行时改变某行的背景 
	e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#eaeaea';");
	//鼠标移走时恢复
	e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;"); 
} 



三:在GridView中点击删除LinkButton时  提示是否删除

前台实现:

 <ItemTemplate>
          <asp:LinkButton ID="LinkDelete" runat="server" Visible ="false" OnClientClick="if(!confirm('确定要删除这条纪录吗?')) return false;"
                       CommandName="lb_delete" Text="删除" CommandArgument='<%#Bind("aa") %>' />
  </ItemTemplate>

后台实现:

//数据绑定时对删除按钮添加提示
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
	//只有数据行才有绑定数据
	if (e.Row.RowType == DataControlRowType.DataRow)
        {
	//由于是链接按钮所以声明一个链接按钮,根据实际情况变动
            LinkButton lnkBtFalg = e.Row.Cells[0].Controls[0] as LinkButton;
            lnkBtFalg.Attributes.Add("onclick", "javascrip:return confirm('您真要的删除吗!')");
        }
    }

四:在服务器端写js脚本  弹出对话提示框

public static void ShowMessage(System.Web.UI.Page thePage,string Text)
        {
            Text = Text.Replace("\"", "").Replace("'", "").Replace("\r", "").Replace("\n", "");
            thePage.ClientScript.RegisterStartupScript(thePage.GetType(), Guid.NewGuid().ToString(),
              "alert('"+Text+"');", true);}

五:Md5加密算法

 public static string Md5Hash(string text)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(text);
            MD5 md5 = MD5.Create();
            byte[] resultBytes=md5.ComputeHash(bytes);//md5

            string md5Result = "";

            for (int i = 0; i < resultBytes.Length; i++)
            {
                md5Result += resultBytes[i].ToString("X2");
            }


            return md5Result;
        }

六:后台显示先提示对话框 后跳转页面

1、Response.Write("<script>alert('查询语句执行出错!');window.location.href=DisplayData.aspx</script>");


2、Page.RegisterStartupScript("msg", "<script>alert('查询语句执行出错!');window.location.href='DisplayData.aspx'</script>");


一般后台弹出提示框,都是用Page.RegisterStartupScript,不用Response.Write的
3、ClientScript.RegisterStartupScript(this.GetType(), " ", " <script lanuage=javascript> alert(' ');location.href=' ';</script>");  


4、System.Web.HttpContext.Current.Response.Write(String.Format("<script language=\"javascript\">alert(\"{0}\");window.location.replace(\"{1}\")</script>", strMessage, strRedirectUrl));


5、ScriptManager.RegisterStartupScript(this, this.GetType(), "u1", "alert('内容!')", true);


6、Page.ClientScript.RegisterStartupScript(this.GetType(), "d", "alert('请先登录!');location='../login.aspx';", true);


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值