魔幻紫光

Nothing is difficult to a willing heart!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ASP.NET基本应用

Posted on 2005-07-19 08:53  魔幻紫光  阅读(734)  评论(0编辑  收藏  举报
连接数据库
<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得到字符串变量里面的字符串所占字节数