曾經記錄——asp.net中的點滴

「<%#....%>」這是數據綁定,裏面能夠調用C#的方法,好比在數據控件裏執行綁定某個字段<%# Eval("Name")%>這樣幫頂一個Name的字段。
「<%@...%>」 這個是頁面指令,通常放在每一個頁面的最頂部,對頁面的運行進行控制,如設置緩存,引用用戶控件,導入命名空間。
「<%= ...%> 」這個=號後也能夠調用C#的方法,還能夠寫數學表達式。 它和 <%#....%> 的區別是, <%#....%> 中的內容必須在後臺代碼中執行了DataBind()方法後才顯示,如<%=DateTime.Now.ToString() %>。
<title><%= ConfigurationManager.AppSettings["ApplicationName"] %></title>
class="<%=ClassName%>" 後臺頁面.cs中的一個 string ClassName變量。
<%# ((DataRowView)Container.DataItem)["xxxx"] %>
<%# ((DataRowView)Container.DataItem).Row["Name"] %>效率最高
<%# DataBinder.Eval(Container.DataItem,"Name") %>
<%# Container.DataItem("Name") %>
<%# Eval("Name")%>html

AttachDbFilename=|DataDirectory|\personnel.mdf; 數據庫文件保存在App_Data特殊文件夾下----相對路徑!~水晶報表。web

CSS中 相對路徑:background-image: url(images/Blue hills.jpg);算法

//若是轉換失敗,轉換結果使用默認值0,不然將轉換結果賦給對應的值
float v1 = 0;
float.TryParse(TextBox1.Text, out v1);數據庫

Page_Init:是在頁面未加載以前,也就是在頁面初始化以前,在Page_Load以前調用的,能夠在控件加載以前作一些客戶端檢測呀這些操做等。但這個事件對於當前用戶來講,只會進行一次,也就是第一次訪問這個頁面的時候,其運行一次。
Page_Load:在Page_Init以後運行(廢話),用於加載控制以及頁面的其它內容。客戶端每刷新或是提交一次,Page_Load事件就從新繪製頁面,將當前頁面當新頁面來處理。c#

if (PreviousPage != null) //PreviousPage 獲取向當前頁 傳輸控件的頁。
TextBox TextBoxName = (TextBox)PreviousPage.FindControl("TextBoxName");
TimeSpan t = new TimeSpan(0, int.Parse(TextBoxTime.Text), 0); //時間隔。瀏覽器

ViewState["t"] = t;緩存

<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>服務器

應用於鏈接的標籤: a:hover{text-decoration:undeline;}
a:link 設定正常狀態下連接文字的樣式;a:active設定鼠標單擊時連接的外觀;a:visited設定訪問過的連接外觀;a:hover設定鼠標放置在連接文字之上時文字的樣式。session

//時間處理。
txtFeedbacktime.Text = DateTime.Now.ToString("yyyy-MM-dd");
fb.feedbacktime = Convert.ToDateTime(this.txtFeedbacktime.Text);
fb.dealtime = System.Data.SqlTypes.SqlDateTime.MinValue;ide

全球惟一標識符 (GUID)是一個字母數字標識符;
System.Guid.NewGuid().ToString() 就是 實例化一個GUID 而且 轉換爲一個 字符串;
記住數據庫的字段設置爲char 或者varchar 38位的!
二、Guid.NewGuid().ToString("D") 結果爲:
57d99d89-caab-482a-a0e9-a0a803eed3ba
三、Guid.NewGuid().ToString("B") 結果爲:
{09f140d5-af72-44ba-a763-c861304b46f8} //可見默認的爲第2種效果
四、GUID id=GUID.newGuid();
-------------
Guid主鍵/算法
--在SQLServer中生成guid的函數:newid() 在列數據屬性中默認值設爲newid();在查詢中select newid();


// 棧-堆棧 !
棧 用於存儲值類型;
堆棧 存儲引用類型,都是在內存中 棧是實際的內存大小 堆棧只是表明相應的棧的內存地址 因此值類型也能夠說棧的存取速度要快

wdkdby00037646@201
121644

委託&事件
private delegate string GetAString()//定義
GetAString firstStringMethod=new GetAString(X.ToString());//像類樣 實例化、
firstStringMethod(); //調用委託類的方法
firstStringMethod.Invoke();//C#編譯器調用的;與上等同;

<%@ Page language="c#" Codebehind="IndicatorDetail.aspx.cs" AutoEventWireup="false" Inherits="Lilosoft.PA.AnalyseStat.AnalyseStat.IndicatorDetail" %>
==============
C# —>EXCEl
--------------
添加引用 COM組件 Microsoft excel 11.0 ;爲office2003
using Excel=Microsoft.Office.Interop.Excel;
Excel.Application elApp=new Excel.Application();
elApp.Visible = true;
Excel.Workbook elBook = elApp.Workbooks.Add(true);
Excel.Worksheet elSheet = (Excel.Worksheet)elBook.Worksheets[1];
elSheet.Cells[1][1] = "第一行,第一列";
-----------------
GC.Collect(); //強制進行垃圾回收
---------------
只有在 Web.config 文件中的 sessionstate 模式設置爲 InProc 時,纔會引起 Session_End 事件
***************
as ——運算符相似於強制轉換操做,進行強制轉換操做。可是,若是沒法進行轉換,則 as 返回 null 而" 非"引起異常.
is 檢查對象是否與給定類型兼容,不進行強制轉換操做。true/false
--------------
js 獲取關閉瀏覽器的操做事件
function checkClose() {
if (event.clientX > document.body.clientWidth - 20 && event.clientY < 0 || event.altKey)
window.event.returnValue = '您肯定退出表單設計器嗎';
}

onbeforeunload="checkClose();"
--------------
Guid主鍵/算法
--在SQLServer中生成guid的函數:newid() 在列數據屬性中默認值設爲newid();在查詢中select newid();
===============

用GridView的OnRowCommand="gridview_RowCommand"事件試試,這個應該能夠

在TemplateField中加入CommandName和CommanArgument如如下方法:
<asp:LinkButton CommandName="SelectReport" CommandArgument='<%# Eval("ID") %>'></asp:LinkButton>

在.cs文件中,代碼相似以下:
protected void gridview_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "SelectReport")
{
string id = e.CommandArgument.ToString(); //這個就是你要取的當前行的ID

....//可能經過這個ID從GridView中查找你要的數據行。
}
}

*******************
GridView1.Rows[GridView1.EditIndex].Cells[6].Controls.Clear();
GridView1.Rows[GridView1.EditIndex].Cells[3].Controls.Add(商品分類);

Gridview1.Rows[GridView1.SelectedIndex].Cell[0].Text //取出值。

-------------------
GridView1.DataKeyNames = new string[] { "id" };//主鍵
string reviewID = this.GWList.DataKeys[e.Row.RowIndex][0].ToString();
--------------
string strName = HttpContext.Current.Request.QueryString["name"];
// QueryString可得到url中的參數
string strRes = "This is the response from the server:/r/n" + "Hello, " + strName + "!";
HttpContext.Current.Response.Clear();//清除緩衝區流中的全部內容輸出。
HttpContext.Current.Response.Write(strRes); //將信息寫入 HTTP 響應輸出流。
HttpContext.Current.Response.Flush();//向客戶端發送當前全部緩衝的輸出。
HttpContext.Current.Response.End();將當前全部緩衝的輸出發送到客戶端,中止該頁的執行,並引起 EndRequest 事件(中止請求)。
-------------
判斷字段是否爲空 !string.IsNullOrEmpty();
-------
PreInit 初始化那一刻
Init
InitComplete 完成初始化
PreLoad 加載到內存那一刻一刻
Load
LoadComplate 完成加載到內存
PreRender
PreRenderComplete 頁面在瀏覽器中顯示前一刻
Unload
-------
WebConfigurationManager類 ++++ machine.config/web.config
----------
Textbox1=(TextBox)PreviousPage.FindControl("Textbox1");//從上一個頁獲取控件.
-----
HtmlContainerControl類>>>
InnerHtml:包涵html元素的內容,InnerText:純文本、
--------
lable控件的內容將顯示在<span>標籤中,而literal則直接顯示內容。
--------
TextBox1.Focus();方法獲取光標、
屬性 AutoCompleteType 快捷地填充信息、
------
button 的causesValidation屬性和commandName屬性(oncommand事件 commandName屬性)
Button 執行完客戶端事件之後再執行服務器事件
------能夠給客戶端事件加一個bool返回值,若是返回false,服務器端不執行,若是返回true,客戶端就執行。
<asp:Button ID="Button1" runat="server" Text="肯定" OnClientClick="return validateMass();" OnClick="Button1_Click" />
---------
bulletedList控件的displayMode屬性設置爲LinkButton能夠onclick事件
---------
hiddenField 控件的 valueChanged事件、
-----------
fileUpload 控件 HttpFileCollection uploadFiles=Request.Files;HttpPostedFile userPostedFile=uploadFiles[i];userPostedFile.SaveAs("\\"+system.IO.Path.GetFileName(userPostedFile.FileName));
-----------
Master頁面在aspx內容頁以後完成,因此aspx內容頁須要在Page_LoadComplete事件中獲取Master頁面中的數據。
在Page_PreInit事件中動態指定Master頁面:Page.MasterPageFile="~/MyMasterPage.master";
-----------
<link rel="icon" href="../sysImages/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="../sysImages/favicon.ico" type="image/x-icon" />
URL左邊的圖標
-------------
獲取當前路徑:string path = HttpContext.Current.Server.MapPath("~/xml/sys/netcms.config");
-------------
JavaScript控件獲取光標:document.getElementById('TxtName').focus();
-------------
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\r<head>\r");
System.Web.HttpContext.Current.Response.End();
-------------
btnSayHello.Attributes.Add("OnClick", "return SetValue(" + input.ClientID + ");");
---------------
System.IO.DriveInfo-->System.IO.Directory/DirectoryInfo-->System.IO.File/FileInfo
------
System.IO.Path
---------------
動態加載用戶控件
Control cl=LoadControl("~/WebUserControl.ascx");
myFrom.Controls.Add(cl);
--------------
例如: <allow users = 「*」>
<deny users = 「?」>
「*」表明全部的用戶,「?」表示匿名(沒通過身份驗證的)用戶。
----------------
在 C# 中引入斷言使用 Debug.Assert() 方法, 若是一切假設都是正確的, 則代碼會
順利的進行.
//index should between 0 to 10
Debug.Assert((index >= 0) && (index <= 10), "Error", "index should between 0 to 10");
return (customers[index] == "James") ? true : false;
----------------
DataBinder.Eval(((RepeaterItem)Container.Parent).DataItem, "CategoryID")。

DataGridItem dgi = (DataGridItem)(((DropDownList)sender).Parent.Parent);

<asp:Repeater id="CategoryLevel2" runat="server" DataSource='<%# GetGlobalCategory(int.Parse(DataBinder.Eval(Container.DataItem, "CategoryID").ToString())) %>'>

========
1Gbit/s=1000*1000bit/8bit/1024=122.0703125Mb/s

 

Asp.net中相對目錄:"../" 本地根"./"上一級"~/"服務器根
相關文章
相關標籤/搜索