最近看了《beginning c# web applications wtith visual studio .net 》。感觉这本书在一些细节方面写的不错,特做笔记,为后来者提供一些或许有用的东东。今天先写出来一些,年前正确整理完。
当前日期:
lbll.text = datetime.now.tolongdatastring();
this.controls.add(lbl);
url:
hyperlink reg = new hyperlink();
reg.text = “register;
reg.navigateurl = context.request.applicationpath + “myfirst.aspx”;
判断用户授权:
context.user.identity.isauthenticated;
表格相关:
1. 新建一图片img
2. img添加到cell
3. cell添加到row
4. row添加到table
5. table添加到placeholder
Table tb = new Table(); TableRow row = new TableRow(); Image img = new Image(); img.ImageUrl = "Images/winbook.gif"; img.ImageAlign = ImageAlign.Middle; img.Width = new Unit(24, UnitType.Pixel); img.Height = new Unit(24, UnitType.Pixel); cell = new TableCell(); cell.Controls.Add(img); row.Cells.Add(cell); HyperLink lnk = new HyperLink(); lnk.Text = "News"; lnk.NavigateUrl = "News.aspx"; row.Cells.Add(cell); tb.Rows.Add(row); phNav.Controls.Add(tb);
将已验证身份的用户重定向回最初请求的URL
public static void RedirectFromLoginPage(string userName,bool createPersistentCookie);
参数
userName
用于 Cookie 身份验证的用户名称。这不需要映射到帐户名称,并将由 URL 身份验证使用。
createPersistentCookie
指定是否应当发出持久性 Cookie(跨浏览器会话保存的 Cookie)。
标准数据库操作1
String sql; SqlCommand cmd; SqlConnection conn; Sql = “insert into …”; conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”); cmd = new SqlCommand (sql,conn); conn.open(); cmd.ExecuteNonQuery();
标准数据库操作2
SqlConnection conn; SqlCommand cmd; SqlDataReader reader; string sql; sql = “select * from TableName”; conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”) cmd = new SqlCommand(sql,conn); conn.open(); reader = cmd.ExecuteReader();
可以用reader的Read()方法判断是否真的返回了值
If (reader.Read())
...{
This.Email.Text = reader[“Email”].ToString();
}
DataSet 基本操作
DataSet dsCaoxicao;
String sql;
SqlConnection conn;
SqlDataAdapter adPlaces;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”)
adPlaces = new SqlDataAdapter(sql,conn);
dsCaoxiCao = new DataSet();
conn.Open();
adPlaces.Fill(dsCaoxiCao,”Places”);以上就是C#Web应用程序入门经典笔记(上册)的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号