一: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);