C#Web應(yīng)用程序入門(mén)經(jīng)典學(xué)習(xí)筆記之二
2024-09-07 17:05:20
供稿:網(wǎng)友
讀取Web.config中設(shè)置
Conn = new SqlConnection(ConfigurationSettings.AppSettings[“cnFriends.ConnectString”]);
<appSettings>
<!-- User application and configured property settings go here.-->
<!-- Example: <add key="settingName" value="settingValue"/> -->
<add key="cnFriends.ConnectionString" value="data source=(local)/NetSdk;initial catalog=FriendsData;user id=sa" /> </appSettings>
幾個(gè)命名空間
當(dāng)用到DataSet時(shí),用using system.Data.SqlClient
當(dāng)配置Web.config時(shí),用using system.Configuration
這個(gè)讓我想起了大一學(xué)習(xí)C語(yǔ)言時(shí)
bool visible
btnSearch.Text = visible? “New Search” : “Search” ;
這個(gè)也蠻好
dsResult.tables[“Users”].rows.count
Conver.Tonint32(ConfigurationSettings.AppSettings[“Cokuale.number”]);
夠狠1:用Session保存結(jié)果并綁定
Session[“Search”] = dsResults;
dsResults = (DataSet) Session[“Search”];
grdResults.DataBind();
其實(shí),Session,Application等存的是object 類型,因此,最后都要顯式轉(zhuǎn)換類型
順便說(shuō)說(shuō),判斷是否取到字符串類型的值用null 判斷。
夠狠2:從DataTable中選擇行
DataRow[] rows = dsResults.Tables[“Users”].Select(filter);
dsResults = dsResults.Clone();
foreach(DataRow row in rows)
{
dsResults.Tables[“Tables”].ImportRow(row);
}
獲取webForm 上的一個(gè)控件
ImageButton img = (ImageButton)e.Item.FindControl(“Selectbutton”)
跳轉(zhuǎn):
Server.Transfer(“Caoxicao.aspx”);
服務(wù)器控件添加js腳本(Attributes屬性)
imgShow.Attributes.Add(“onclick”,”document.getElementById(‘tbPrefs').style.display = ‘block';”);
再(Style屬性),
img.Style.Add(“Cursor”,'Pointer');
Color相關(guān):
ColorConvert cv = new ColorConvert();
Color selected = Color.Empty;
Selected = (olor)cv.ConvertFromString(White);
增加Cookie
Response.Cookies.Add(new HttpCookie(“backColor”,r))
我的最愛(ài)----用戶控件
Using FriendsReunion.Controls;
Protectd override void Oninit(EventArgs e)
{
FriendsFooter _footer = (FriendsFooter)LoadControl(Request.ApplicationPath+”/Controls/ FriendsFooter.aspx”);