當(dāng)前日期:

Lbll.Text " /> 国产乱论精品,亚洲黄色免费av,亚洲一区二区精品

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

C#Web應(yīng)用程序入門經(jīng)典學(xué)習(xí)筆記之一

最近看了《Beginning C# Web Applications Wtith Visual Studio .NET 》。感覺這本書在一些細(xì)節(jié)方面寫的不錯(cuò),特做筆記,為后來者提供一些或許有用的東東。今天先寫出來一些,年前正確整理完。

   當(dāng)前日期:

Lbll.Text = DateTime.Now.ToLongDataString();
This.controls.Add(lbl);

URL:

HyperLink reg = new HyperLink();
Reg.Text = “Register;
Reg.NavigateUrl = Context.Request.ApplicationPath + “Myfirst.ASPx”;

判斷用戶授權(quán):

Context.User.Identity.IsAuthenticated;

表格相關(guān):

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);

將已驗(yàn)證身份的用戶重定向回最初請(qǐng)求的URL

public static void RedirectFromLoginPage(string userName,bool createPersistentCookie);

參數(shù)
userName 
用于 Cookie 身份驗(yàn)證的用戶名稱。這不需要映射到帳戶名稱,并將由 URL 身份驗(yàn)證使用。 
createPersistentCookie 
指定是否應(yīng)當(dāng)發(fā)出持久性 Cookie(跨瀏覽器會(huì)話保存的 Cookie)。

標(biāo)準(zhǔn)數(shù)據(jù)庫操作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();

標(biāo)準(zhǔn)數(shù)據(jù)庫操作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”);

AspNet技術(shù)C#Web應(yīng)用程序入門經(jīng)典學(xué)習(xí)筆記之一,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 武强县| 蒲城县| 宜宾市| 临潭县| 甘孜县| 禹城市| 依安县| 武冈市| 眉山市| 西安市| 潍坊市| 牙克石市| 宜良县| 贡嘎县| 长丰县| 环江| 腾冲县| 赣榆县| 高台县| 休宁县| 凉山| 萍乡市| 宁明县| 和静县| 正蓝旗| 西充县| 施秉县| 冕宁县| 忻城县| 闽侯县| 唐山市| 平武县| 罗源县| 吉木萨尔县| 遂川县| 方正县| 江陵县| 广州市| 河池市| 湘阴县| 苍南县|