ASP.NET基本應用

來源:互聯網
上載者:User
串連資料庫
<appSettings>
 <add key="sqllink" value="server=yfq-001;uid=ADM;pwd=sdadm;database=DBMT50"></add>
 <add key="sqllink1" value="server=ymc;uid=sa;pwd=;database=Northwind"></add>
</appSettings>
開啟串連
string connstr=System.Configuration.ConfigurationSettings.AppSettings["sqllink"];
SqlConnection conn=new SqlConnection(connstr);
conn.Open();
添加DataGrid
SqlDataAdapter dr=new SqlDataAdapter(sqlstr,conn);
DataSet ds=new DataSet();
dr.Fill(ds,"usract");
if(Convert.ToInt32(ds.Tables["ContList"].Rows.Count.ToString())==0)
{
    this.DataGrid1.ShowFooter=true;
}
this.DataGrid1.DataSource=ds.Tables["usract"].DefaultView;
this.DataGrid1.DataBind(); 
ADO.NET應用
string sql="select count(*) as icount from sysoper where logname='"+this.usrname.Text+"'";
SqlCommand comm=new SqlCommand(sql,conn);
SqlDataReader dr1=comm.ExecuteReader();
dr1.Read();
string count=dr1["icount"].ToString();
dr1.Close();
panel顯示條
<asp:Panel id="Panel1" style="Z-INDEX: 101; LEFT: 64px; OVERFLOW: scroll; POSITION: absolute; TOP: 288px" runat="server" Height="192px" Width="568px">
DIV捲軸
<DIV id="SelectShow1" style="OVERFLOW-Y: auto; OVERFLOW-X: auto; WIDTH: 83.08%; HEIGHT: 104px">
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
</DIV>
enconding加密
System.Web.HttpUtility.UrlEncode(this.txtgrpid.Text.Trim())
System.Web.HttpUtility.HtmlDecode(Request.QueryString["grpid"])

時間格式
d 月中的某一天。一位元的日期沒有前置字元為零。
dd 月中的某一天。一位元的日期有一個前置字元為零。
ddd 周中某天的縮寫名稱,在 AbbreviatedDayNames 中定義。
dddd 周中某天的完整名稱,在 DayNames 中定義。
M 月份數字。一位元的月份沒有前置字元為零。
MM 月份數字。一位元的月份有一個前置字元為零。
MMM 月份的縮寫名稱,在 AbbreviatedMonthNames 中定義。
MMMM 月份的完整名稱,在 MonthNames 中定義。
y 不包含紀元的年份。如果不包含紀元的年份小於 10,則顯示不具有前置字元為零的年份。
yy 不包含紀元的年份。如果不包含紀元的年份小於 10,則顯示具有前置字元為零的年份。
yyyy 包括紀元的四位元的年份。
gg 時期或紀元。如果要設定格式的日期不具有關聯的時期或紀元字串,則忽略該模式。
h 12 小時制的小時。一位元的小時數沒有前置字元為零。
hh 12 小時制的小時。一位元的小時數有前置字元為零。
H 24 小時制的小時。一位元的小時數沒有前置字元為零。
HH 24 小時制的小時。一位元的小時數有前置字元為零。
m 分鐘。一位元的分鐘數沒有前置字元為零。
mm 分鐘。一位元的分鐘數有一個前置字元為零。
s 秒。一位元的秒數沒有前置字元為零。
ss 秒。一位元的秒數有一個前置字元為零

 

快顯視窗:
Response.Write("<script>window.alert('您已經註冊成功!')</script>");
Response.Write("<script>window.top.location='index.aspx'</script>");
vs.net2005 b2的啟用號:
NGBQ2KCKL31K00
vs.net2003和vs.net2005 b1的使用:
用2003
c:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -i
c:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -r
用2005
c:\WINNT\Microsoft.NET\Framework\v2.0.40607\aspnet_regiis.exe -i
c:\WINNT\Microsoft.NET\Framework\v2.0.40607\aspnet_regiis.exe -r
如何去掉str後x位字元?只要前面的字元:
string tmp = str.SubString(0,str.Length-x);
如何保留str前i位字元:
string tmp = str.SubString(0,i);
如何去掉str前i位字元:
string tmp = str.SubString(x);
如何去掉str中的abc字元,如果有的話:
string tmp = str.Replace("abc","");
跳出這個if語句用break
跳出函數用return
當傳回值是void的時候用return;
當傳回值有具體資料類型的時候要返回相應的資料類型。
//跳頁
this.Response.Write("<script>window.location.href='contlist.aspx'</script>");
//關閉
this.Response.Write("<script language=javascript>window.close();</script>");
//快顯視窗重新整理當前頁面width=200 height=200菜單。工具條沒有
//this.Response.Write("<script language=javascript>window.open('rows.aspx','newwindow','width=200,height=200')</script>");
//快顯視窗重新整理當前頁面有菜單。工具條
//Response.Write("<script language=javascript>window.open('rows.aspx')</script>");
//快顯視窗重新整理當前頁面有菜單。工具條。快顯視窗置中
//Response.Write("<script>window.open('rows.aspx','_blank');</" + "script>");
//快顯視窗重新整理當前頁面有菜單。工具條。
//this.RegisterStartupScript("OpenNewPage","<script language=javascript>window.open('rows.aspx?ID="+e.ToString()+"','_blank');</script>");
//單點第一頁重新整理第二頁
Response.Write("<script language=javascript>window.opener.location.href=window.opener.location.href</script>"); 
//重新整理父關閉當前
Response.Write("<script language='javascript'>window.opener.location.href=window.opener.location.href;window.close();</script>");
Response.Write("<script language='javascript'>window.opener.location.href=window.opener.location.href;window.close();</script>");
this.Response.Write("<script language=javascript>window.open('WebForm3.aspx','newwindow','width=200,height=200,top=200,left=400')</script>");
this.Response.Write("<script language=javascript>window.open('WebForm3.aspx','_blank','width=200,height=200,top=200,left=400');</script>");
ip地址的使用:
string hostIP=System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0].ToString();
this.Image1.ImageUrl="http://"+hostIP+"/mtamap/000001.bmp";
//利用主機ip127.0.0.1得到主機名稱字
IPHostEntry hostInfo=Dns.GetHostByAddress("127.0.0.1");
string hostname=hostInfo.HostName.ToString();
//定位到另一個目錄
string url="http://"+hostname+"/mtamap/"+Session["str"].ToString()+".bmp";
this.Response.Redirect(url);
//隱藏功能表列地址欄工具條的IE,以下變數分別是新視窗的名字,視窗的寬度、高度,有捲軸,視窗距離螢幕上方和左側的象素  //e.Item.Attributes.Add("onclick","window.open('pdetail.aspx?ID="+e.Item.Cells[1].Text+"','newwin','width=750,height=600,scrollbars=yes,top=50,left=50');");
string s="abc村械地23423";
int byteCount=System.Text.Encoding.Default.GetByteCount(s);
byteCount得到字串變數裡面的字串所佔位元組數

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.