一、 關於DataGrid的分頁
除了設定:
AllowPaging是指允許分頁,這個是最主要的。有了它,我們才能分頁。
PageSize是指定每頁顯示的記錄數,如果不寫,就會預設為10條。
外,還要加入:
OnPageIndexChanged="DataGrid1_PageIndexChanged"
public void DataGrid1_PageIndexChanged(object sender, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex =e.NewPageIndex;
DataGrid1.DataBind();
}
二、 關於上傳檔案
上傳檔案應加入:
<form id="Form1" enctype="multipart/form-data" method="post" runat="server">
源檔案裡邊加入:
if(File1.PostedFile !=null)
{
File1.PostedFile.SaveAs (Server.MapPath ("\\1.jpg"));
Image1.ImageUrl =Server.MapPath ("\\1.jpg");
}
三、 關於自動重新整理
HTML應加入:
<meta http-equiv ="REFRESH" content ="10;URL=chat.aspx">
自動視窗ScrollWindow():
<script language =javascript 1.1>
function scrollWindow()
{
this.scroll(0,65000);
setTimeout('scrollWindow()',200);
}
scrollWindow();
</script>
四、 連到SQL資料庫
string _sql;
SqlConnection cn;
_sql="server=localhost;uid=sa;pwd=hz0222;database=Northwind";
cn=new SqlConnection (_sql);
cn.Open ();
//SqlCommand cmd =new SqlCommand ("select * from Products ",cn);
//SqlDataReader rs;
//rs=cmd.ExecuteReader();
SqlDataAdapter da=new SqlDataAdapter ("select * from Products",cn);
DataSet ds=new DataSet ();
da.Fill (ds,"Products");
DataGrid1.DataSource =ds.Tables["Products"].DefaultView ;
//DataGrid1.CurrentPageIndex = 0;
DataGrid1.DataBind ();
cn.Close ();
五、 查詢IP地址
private void Button6_Click(object sender, System.EventArgs e)
{
IPHostEntry hostInfo = Dns.GetHostByName(txtDomain.Text);
Response.Write ("<br>" +hostInfo.AddressList[0].ToString());
}
當然記得用引名字空間 System.Net
六、 在HTML中載入處理頁面
<form method="post" action="index2.aspx">
七、 使用TreeView控制項
a) 下載並安裝IEWebControls:http://www.asp.net/IEWebControls/Download.aspx
b) 安裝完以後,預設狀態下會建立一個目錄:\Program files\IEWeb Controls\,當然你也可改變安裝目錄。找到這個目錄,雙擊build.bat檔案執行,它會建立一個名為build的子目錄,並且編譯在src目錄下的源檔案,把編譯結果和Runtime目錄複寫到build子目錄中(自動)。在這個動作之後,在build目錄下應該會有一個叫"Microsoft.Web.UI.WebControls.dll"檔案和一個Runtime子目錄。為了能在ASP.NET的Web應用程式中使用這個控制項,你必須把\build\Runtime子目錄下的內容複寫到Web應用程式的 /webctrl_client/1_0子目錄中,並且把"Microsoft.Web.UI.WebControls.dll"這個檔案複製到Web應用程式的/bin目錄下。這個過程在Readme.txt檔案有詳細的說明,不過是英文的。
c) 然後,你就可以在Toolbox中添加一個工具了(這個不用說明了吧)
d) 以下是WebControls的說明書(E文)
To run the IE Web Controls:
1. Copy the contents of the Runtime directory to the webctrl_client\1_0
directory under your top-level site directory. For example, if your
site root is c:\Inetpub\wwwroot, type this at the command prompt:
xcopy /s /i .\build\Runtime c:\Inetpub\wwwroot\webctrl_client\1_0 /y
This will create the following directory structure under the site:
/webctrl_client/1_0
MultiPage.htc
TabStrip.htc
toolbar.htc
treeview.htc
webservice.htc
webserviced.htc
[images]
[treeimages]
2. Create a new web application in IIS and copy the contents of the
samples directory to this application directory. For example:
xcopy /s /i .\samples c:\Inetpub\wwwroot\sampleapp /y
3. Create a /bin subdirectory for the application and copy the file
Microsoft.Web.UI.WebControls.dll to this directory.
The contents of the application will be as follows:
/sampleapp
multipage.aspx
state_city.xml
tabstrip.aspx
toolbar.aspx
treeview.aspx
treeview_bound.aspx
/bin
Microsoft.Web.UI.WebControls.dll
4. Request the sample pages from your Internet Explorer web browser, for
example: http://localhost/sampleapp/multipage.aspx
八、 取消IEAlibaba Content Security Service驗證
a) validateRequest="false"
九、 第三方的Dtable控制項使用方法
a) 一定要把HTML中的<form……去掉
b) 所串連的表的第一個欄位必需是自動編號的int類型,Sql的驗證最好加上ASP.NET這個帳號
c) 其它問題請參考論壇http://dtable.2smm.com