国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#Web應用程序入門經典學習筆記之二

2020-01-18 01:55:33
字體:
來源:轉載
供稿:網友
讀取Web.config中設置

   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>

 


幾個命名空間

當用到DataSet時,用using system.Data.SqlClient

當配置Web.config時,用using system.Configuration


這個讓我想起了大一學習C語言時

bool visible

btnSearch.Text = visible? “New Search” : “Search” ;


這個也蠻好

dsResult.tables[“Users”].rows.count

Conver.Tonint32(ConfigurationSettings.AppSettings[“Cokuale.number”]);


夠狠1:用Session保存結果并綁定

Session[“Search”] = dsResults;

dsResults = (DataSet) Session[“Search”];

grdResults.DataBind();
其實,Session,Application等存的是object 類型,因此,最后都要顯式轉換類型
順便說說,判斷是否取到字符串類型的值用null 判斷。

夠狠2:從DataTable中選擇行

DataRow[] rows = dsResults.Tables[“Users”].Select(filter);

dsResults = dsResults.Clone();

foreach(DataRow row in rows)

{

         dsResults.Tables[“Tables”].ImportRow(row);

}


獲取webForm 上的一個控件

ImageButton img = (ImageButton)e.Item.FindControl(“Selectbutton”)


跳轉:

Server.Transfer(“Caoxicao.aspx”);


服務器控件添加js腳本(Attributes屬性)

imgShow.Attributes.Add(“onclick”,”document.getElementById(‘tbPrefs').style.display = ‘block';”);
再(Style屬性),

img.Style.Add(“Cursor”,'Pointer');


Color相關:

ColorConvert cv = new ColorConvert();

Color selected = Color.Empty;

Selected = (olor)cv.ConvertFromString(White);


增加Cookie

Response.Cookies.Add(new HttpCookie(“backColor”,r))


我的最愛----用戶控件

Using FriendsReunion.Controls;

Protectd override void Oninit(EventArgs e)

{

         FriendsFooter _footer = (FriendsFooter)LoadControl(Request.ApplicationPath+”/Controls/ FriendsFooter.aspx”);

         SubHeader _subHeader = new SubHeader();

}

Page.Contros.AddAt(0,_footer);

Page.Contros.AddAt(0,_subHeader);

base.OnInit(e);

}


新建Html控件實例

HtmlGenericControl div = new HtmlGenericControl(“div”);

div.Style.Add(“background-color”,bg);

使用該類可以表示不直接用 .NET Framework 類表示的 HTML 服務器控件標記,如 <span>、<div>、<body> 和 <font>


返回DataSet

Public DataSet Contact()

{

         String sql = “@ Select * from … …”;

         DataSet requests = new DataSet();

         New SqlDtaAdapter (sql,conn).Fill(requests);

         //return requests.GetXml();
                   Return requests;

}

接收:(當返回值是Xml格式的數據集時)

DataSet results = new DataSet();

Results.ReadXml(new StringReader(fi.ContactRequest(userid)));


用到WebService時,只需在方法上添加[WebMethod]特性即可!

如果添加緩存,則[WebMethod(CacheDurition=600)]

實例化WebService

FriendsService.FriendsInfo fi = new FriendsService.FriendsInfo();

String userid;

Userid = fi.GetUserID(“…”);


小Tips!

HyperLink reg = new HyperLink();

Reg.ToolTip = “… …”;


簽出:

System.Web.Security.Forms.Authentication.SignOut();

Response.write (Request.ApplicaltionPath);


跟蹤調試:

Trace.Write

Trace.Warn


異常:

1.   拋出異常

         程序異常拋出

         Throw new ***Exception(“…”);

2.   捕獲異常

         必須開始時從一個try代碼塊拋出,try代碼塊用來放置所有可能拋出異常的代碼。

Eg:

         Try

                  {

                            … …

                  }

         Catch(ArgumentNullExeption e)

                  {

                            …

                  }

 

未處理異常web.config設置

<Custom Errors mode = “on” defaultRedriect = “customerror.aspx”; />

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 松原市| 策勒县| 吉林省| 疏勒县| 衡阳县| 彩票| 沙湾县| 永平县| 永福县| 扶风县| 合阳县| 日喀则市| 拉萨市| 玉田县| 密山市| 周宁县| 东平县| 海林市| 邯郸县| 古田县| 巴彦淖尔市| 义乌市| 灯塔市| 都匀市| 杂多县| 方城县| 嘉峪关市| 安塞县| 库伦旗| 湘阴县| 琼中| 资中县| 邵阳市| 米泉市| 溆浦县| 呼玛县| 新巴尔虎左旗| 顺平县| 上林县| 柳林县| 枣阳市|