Time of Update: 2018-12-08
根據某列的值改變其樣式最好的方法是在GridView的DataRowBound事件中想辦法。在GridView中的行綁定資料後將立即執行DataRowBound事件。DataRowBound事件使用GridViewRowEventargs類作為事件變數。通過事件變數你能夠利用GridViewRowEventArgs屬性操作已經綁定資料的行。複製代碼 代碼如下:protected void GridView1_RowDataBound(object sender,
Time of Update: 2018-12-08
以下為設計步驟:1、在C#
Time of Update: 2018-12-08
但是這個變數不會一個固定的值,會根據實際情況而發生變化,比如在需要讀取一個設定檔的路徑,而這個路徑是網站發布的實際硬碟路徑,如果直接是編譯時間狀態,沒有問題。但是如果網站iis更換路徑,就需要修改這個web.config中的參數。如果能將這個編譯時間狀態修改為運行時狀態,那將更為合理和方便。這就需要存在一種在代碼中能夠動態修改web.config的方案。 代碼複製代碼 代碼如下: /// <summary> /// 寫入web.config /
Time of Update: 2018-12-08
在 ASP.NET MVC 4 中可捆綁多個 css 和 js 檔案以減少HTTP請求,並對 css 和 js 檔案進行壓縮(縮小),這樣可提高網站的載入速度。我們選取部落格園的 css 檔案來看看,在 ASP.NET MVC 4 前,我們引入 css 方法如下: 複製代碼 代碼如下:<link href="/Content/Site.css" rel="stylesheet" type="text/css" /> <link
Time of Update: 2018-12-08
1.頁面緩衝 要實現網頁輸出快取,只要將一條 OutputCache 指令添加到頁面即可。 <%@ OutputCache CacheProfile=" " NoStore="True | False" Duration="#ofseconds" Shared="True | False" Location="Any | Client | Downstream | Server | None | ServerandClient "
Time of Update: 2018-12-08
ASP.NET請求驗證功能為我們提供應用程式的安全保證,避免網站受到XSS跨站指令碼攻擊。但在有些時候,比如我們需要使用Ckeditor等線上文字編輯器讓使用者輸入一些HTML文本,在ASP.NET 2.0架構下,通過在web.config中設定validateRequest="false"。或者在MVC中,我們可以通過在Controller或者Action上設定[ValidateRequest(false)]這個特性來達到禁用的目的。但是在ASP.NET 4.0架構下,你會發現,即使你這樣做,
Time of Update: 2018-12-08
[html]複製代碼 代碼如下:<div id="demo" style="overflow: hidden; width: 441px; border: 0px"> <table width="441" height="130" border="0" cellpadding="0" cellspacing="0" background="Images/img2/32.jpg"> <tr>
Time of Update: 2018-12-08
MVC下: 後台代碼: 複製代碼 代碼如下:public ActionResult sys(string page) { if (page == null) { string sql = "select top 15 * from dingdinfo ORDER BY dingdh desc"; ViewData["ds"] = dr.resultSet(sql, "dingdinfo"); } if (page != null) { int pageSL =
Time of Update: 2018-12-08
複製代碼 代碼如下:#region DataTable匯出到Excel /// <summary> /// DataTable匯出到Excel /// </summary> /// <param name="pData">DataTable</param> /// <param name="pFileName">匯出檔案名稱</param>
Time of Update: 2018-12-08
假設你已經瞭解ASP.NET Eval 1.1的資料繫結(特別是Container這個局部變數)的機制,這裡主要分析ASP.NET Eval 2.0資料繫結做了那些改進.ASP.NET Eval 2.0 的資料繫結函數Eval()簡化掉了ASP.NET Eval 1.1神秘的Container.DataItem,比如資料繫結運算式:複製代碼 代碼如下:<%# (Container.DataItem as DataRowView)["ProductName"].ToString()
Time of Update: 2018-12-08
複製代碼 代碼如下://必須的命名空間using System;using System.Data;using System.Data.SqlClient;//中間常規內容略string tabName = "table1";//聲明要建立的表名,你也可以改為從textbox中擷取;string sqlStr = "create table ";sqlStr += tabName + "( ";sqlStr += "col0 numeric identity(1,1) primary key,"
Time of Update: 2018-12-08
編輯gridview例子,完整代碼如下。複製代碼 代碼如下:protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { GridView1.EditIndex = e.NewEditIndex; BingGrid(); } protected void GridView1_RowCancelingEdit(object sender,
Time of Update: 2018-12-08
1、Request 下面做一個執行個體,通過Request的一些方法來判斷瀏覽圖片是不是在內部瀏覽,還是直接按網址瀏覽或者被外部使用複製代碼 代碼如下:<%@ WebHandler Language="C#" Class="image_Test" %> using System; using System.Web; public class image_Test : IHttpHandler { public void
Time of Update: 2018-12-08
1、httphandler 執行個體1:通過產生一張動態圖片輸出用戶端的IP地址、作業系統類型、瀏覽器類型複製代碼 代碼如下:<%@ WebHandler Language="C#" Class="visitor" %>using System;using System.Web;public class visitor : IHttpHandler { public void ProcessRequest(HttpContext context) {
Time of Update: 2018-12-08
1、ASP.NET的好壞處CodeBehind:“前aspx後cs”的模式,(1、aspx(控制項定義、html、css)控制頁面長相,cs控製程序邏輯aspx就是模板引擎,不需要再去尋找第三方的模板引擎(2、aspx中調用cs的成員層級必須是protected或者public不能是private因為當前this執行的是當前的子類(通過反編譯查看)2、Literal: Mode屬性,避免XSS攻擊TextBox:AutopostBack=true
Time of Update: 2018-12-08
1、(1、預設情況下ASP.Net是啟用ViewState的,這樣在頁面中會產生冗長的隱藏欄位,ViewState對於需要PostBack處理的頁面才可能有用,對於新聞展示頁面不需要互動完全沒必要用ViewState。(2、禁用ViewState的方式:• 頁面整體禁用ViewState:在頂部Page中EnableViewState="False"•
Time of Update: 2018-12-08
url重寫的好處:1,方便搜尋引擎檢索到(html格式的網站搜尋引擎記住的優先順序最高,seo最佳化更好)2,url更加簡潔,方便使用者記憶3,隱藏網頁的實際路勁和具體開發技術使用URLRewriter.dll重寫使用URLRewriter.dll後,只需要使用如下步驟將可以進行url重寫1,在webconfig下寫入複製代碼 代碼如下:<Rules> <!-- 規則1 --> <RewriterRule>
Time of Update: 2018-12-08
ASP.NET中,CheckBoxList裡的選擇都是自動寬度的,屬性時沒有設定各項寬度的設定。 參考了一下網上的最小寬度樣式, 複製代碼 代碼如下:/* 最小寬度 */ .min_width{min-width:300px; /* sets max-width for IE */ _width:expression(document.body.clientWidth < 300 ? "300px" : "auto"); } 寫成如下: 複製代碼 代碼如下:<style>
Time of Update: 2018-12-08
複製代碼 代碼如下:protected void Button1_Click(object sender, EventArgs e) { /* 微軟為Response對象提供了一個新的方法TransmitFile來解決使用Response.BinaryWrite 下載超過400mb的檔案時導致Aspnet_wp.exe進程回收而無法成功下載的問題。 代碼如下: */ Response.ContentType = "application/x-zip-compressed";
Time of Update: 2018-12-08
複製代碼 代碼如下: PagedDataSource objPage = new PagedDataSource(); DataView dv = bllBook.GetListByState("", true); //設定資料來源 objPage.DataSource =dv ; //允許分頁 objPage.AllowPaging = true;