1.簡單數(shù)據(jù)綁定定

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

ASP.NET 2.0 綁定高級技巧

系統(tǒng) 3090 0
<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>

1.簡單數(shù)據(jù)綁定定

<!--</span><span style="COLOR: #008000">ASP.NET1.xdatabindingexpression</span><span style="COLOR: #008000">-->
#DataBinder.Eval(Container.DataItem, " Price " ) %>
<!--</span><span style="COLOR: #008000">EquivalentASP.NET2.0databindingexpression</span><span style="COLOR: #008000">-->
# Eval ( " Price " ) %>
<!--</span><span style="COLOR: #008000">XMLdatabinding</span><span style="COLOR: #008000">-->
#XPath( " Price " ) %>
2.數(shù)據(jù)源控件
控件名 控件描述
SqlDataSource 一切支持SQL語句的數(shù)據(jù)源控件
AccessDataSource Access數(shù)據(jù)源控件
XmlDataSource XML數(shù)據(jù)源控件
ObjectDataSource 自行編寫組件的數(shù)據(jù)源控件
SiteMapDataSource頁面導(dǎo)航控件的數(shù)據(jù)源控件
2.1 SqlDataSource關(guān)鍵屬性
名稱 描述
ConnectionString 連接數(shù)據(jù)庫的連接字符串
SelectCommand 用于執(zhí)行查詢的命令
InsertCommand 用于執(zhí)行插入的命令
UpdateCommand用于執(zhí)行更新的命令
DeleteCommand 用于執(zhí)行刪除的命令
DataSourceMode 指定數(shù)據(jù)源類型是DataSet或DataReader(默認(rèn)值
= DataSet)
ProviderName 指定供應(yīng)商(默認(rèn)值
= SQLServer.NETprovider)
2.2 SqlDataSource 支持通過以下屬性進(jìn)行數(shù)據(jù)緩存
屬性名 描述
EnableCaching 指定是否打開緩存(默認(rèn)值
= false )
CacheDuration 指定結(jié)果被緩存多少妙
CacheExpirationPolicy指定緩存間隔是sliding還是absolute
CacheKeyDependency 使緩存依賴于一個(gè)特定鍵值
SqlCacheDependency 使緩存依賴于一個(gè)特定數(shù)據(jù)庫實(shí)體
2.3 參數(shù)化命令 XxxParameter 類型指定參數(shù)來源
名稱 描述
SelectParameters 為查詢命令指定參數(shù)
InsertParameters 為插入命令指定參數(shù)
UpdateParameters 為更新命令指定參數(shù)
DeleteParameters 為刪除命令指定參數(shù)
FilterParameters 為過濾器命令指定參數(shù)
2.4 XxxParameter 類型
名稱 描述
ControlParameter 指定一個(gè)源自于控件的參數(shù)
CookieParameter指定一個(gè)源自于cookie的參數(shù)
FormParameter 指定一個(gè)源自于表單的參數(shù)
ProfileParameter 指定一個(gè)源自于profile的參數(shù)
QueryStringParameter制定于一個(gè)來源于查詢字符串的參數(shù)
Parameter 為數(shù)據(jù)源綁定一個(gè)參數(shù)
SessionParameter 指定一個(gè)源自于session的參數(shù)
2.5 使用ControlParameter例子
asp:SqlDataSourceID ="Countries" RunAt ="server"
ConnectionString
="server=localhost;database=northwind;"
SelectCommand
="selectdistinctcountryfromcustomersorderbycountry" />
asp:SqlDataSourceID ="Customers" RunAt ="server"
ConnectionString
="server=localhost;database=northwind;"
SelectCommand
="select*fromcustomerswherecountry=@Country" >
SelectParameters >
asp:ControlParameterName ="Country" ControlID ="MyDropDownList"
PropertyName
="SelectedValue" />
SelectParameters >
asp:SqlDataSource >
asp:DropDownListID ="MyDropDownList" DataSourceID ="Countries"
DataTextField
="country" AutoPostBack ="true" RunAt ="server" />
asp:DataGridDataSourceID ="Customers" RunAt ="server" />
2.7 調(diào)研存儲過程例子
asp:SqlDataSourceID ="Countries" RunAt ="server"
ConnectionString
="server=localhost;database=northwind;"
SelectCommand
="proc_GetCountries" />
asp:SqlDataSourceID ="Customers" RunAt ="server"
ConnectionString
="server=localhost;database=northwind;"
SelectCommand
="proc_GetCustomers" >
SelectParameters >
asp:ControlParameterName ="Country" ControlID ="MyDropDownList"
PropertyName
="SelectedValue" />
SelectParameters >
asp:SqlDataSource >
asp:DropDownListID ="MyDropDownList" DataSourceID ="Countries"
DataTextField
="country" AutoPostBack ="true" RunAt ="server" />
asp:DataGridDataSourceID ="Customers" RunAt ="server" />
CREATEPROCEDUREproc_GetCustomers
@Countrynvarchar(32)AS
SELECT*FROMCustomers
WHERECountry=@Country
GO
CREATEPROCEDUREproc_GetCustomers
CREATEPROCEDUREproc_GetCountriesAS
SELECTDISTINCTCountry
FROMCustomers
ORDERBYCountry
GO
3.XmlDataSource 使用XML 作為數(shù)據(jù)源
支持緩存與XSL 轉(zhuǎn)換,只支持查詢綁定,不支持更新
asp:XmlDataSourceID ="Rates" DataFile ="Rates.xml" RunAt ="server" />
asp:TreeViewID ="MyTreeView" DataSourceID ="Rates" RunAt ="server" />
3.1 XmlDataSource的關(guān)鍵屬性
名稱 描述
DataFileXML 數(shù)據(jù)文件的路徑
TransformFile 含有XSL風(fēng)格定義的數(shù)據(jù)文件路徑
EnableCaching 指定是否開啟cache(默認(rèn)值 = false )
XPathXPath 表達(dá)式用來確認(rèn)數(shù)據(jù)
CacheDuration 以秒為單位的時(shí)間間隔
CacheExpirationPolicy 指定時(shí)間間隔是sliding還是absolute
CacheKeyDependency 創(chuàng)建緩存依存于某個(gè)鍵
4. ObjectDataSource
從數(shù)據(jù)組件綁定數(shù)據(jù),提供中間件的數(shù)據(jù)綁定,使數(shù)據(jù)訪問和UI脫離,兩種數(shù)據(jù)綁定方式
SelectMethod, InsertMethod, UpdateMethod,and DeleteMethod
可選擇是否使用緩存,可選擇是否使用參數(shù)
4.1 ODS 關(guān)鍵屬性
ODS關(guān)鍵屬性
名稱 描述
InsertParameters 指定插入方法參數(shù)
UpdateParameters 指定更新方法參數(shù)
DeleteParameters 指定刪除方法參數(shù)
SelectParameters 指定查詢方法參數(shù)
CacheDuration 緩存間隔時(shí)間以秒為單位
SqlCacheDependency 基于某個(gè)數(shù)據(jù)實(shí)體的緩存
創(chuàng)建和清除
ObjectDataSource.SelectMethod可以使用靜態(tài)方法也可以使用一個(gè)類的新實(shí)例
如果使用實(shí)例方法:ODS在每次調(diào)用的時(shí)候創(chuàng)建一個(gè)新實(shí)例類必須具有公共的建構(gòu)函數(shù)
使用ObjectCreated和ObjectDisposing元素可以初始化和撤銷函數(shù)
5.增強(qiáng)的DataGrid 控件
支持復(fù)雜的數(shù)據(jù)單元格類型,包括CheckBoxFields在<columns> 元素中聲明高可定制的用戶界面<br>gridView 列類型:<br><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <img alt="" src="http://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif" align="top"><span style="COLOR: #000000">名稱 描述<br><img alt="" src="http://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif" align="top">BoundField 顯示數(shù)據(jù)庫中取出的文本<br><img alt="" src="http://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif" align="top">ButtonField 顯示按鈕<br><img alt="" src="http://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif" align="top">CheckBoxField 使用checkboxes顯示一個(gè)boolean型變量<br><img alt="" src="http://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif" align="top">HyperLinkField 顯示一個(gè)超鏈接<br><img alt="" src="http://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif" align="top">TemplateField 顯示一個(gè)自定義的HTML模板<br><img alt="" src="http://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif" align="top">CommandField 顯示一個(gè)查詢或者編輯按鈕<br><img alt="" src="http://ghd258.cnblogs.com/Images/OutliningIndicators/None.gif" align="top">ImageField 顯示一個(gè)圖片</span> </div></columns>6. 沖突判定
先入勝利
如果數(shù)據(jù)在取出之后被改變,則修改失敗
UpdateCommand結(jié)構(gòu)構(gòu)成指定ConflictDetection
= “CompareAllValues”來實(shí)現(xiàn)
后入勝利
無論數(shù)據(jù)是否被修改,該修改都會成功
UpdateCommand結(jié)構(gòu)構(gòu)成指定ConflictDetection
= “OverwriteChanges”來實(shí)現(xiàn)
6.1 先入勝利法則更新
asp:SqlDataSourceID ="Employees" RunAt ="server"
ConnectionString
="server=localhost;database=northwind;"
SelectCommand
="selectemployeeid,lastname,firstnamefromemployees"
UpdateCommand
="updateemployeessetlastname=@lastname,firstname=
@firstnamewhereemployeeid=@original_employeeidandlastname=
@original_lastnameandfirstname=@original_firstname"

ConflictDetection
="CompareAllValues" >
UpdateParameters >
asp:ParameterName ="EmployeeID" Type ="Int32" />
asp:ParameterName ="lastname" Type ="String" />
asp:ParameterName ="firstname" Type ="String" />
UpdateParameters >
asp:SqlDataSource >
asp:GridViewDataSourceID ="Employees" Width ="100%" RunAt ="server"
DataKeyNames
="EmployeeID" AutoGenerateEditButton ="true" />
7.錯(cuò)誤檢測
數(shù)據(jù)更新后控件調(diào)用的事件GridView.RowUpdated,DetailsView.ItemUpdated,SqlDataSource.Updated, etc.
處理“status”的事件,無論數(shù)據(jù)庫是否異常允許數(shù)據(jù)庫異常被處理或者再次拋棄,顯示多少數(shù)據(jù)庫行被修改
處理更新錯(cuò)誤
asp:SqlDataSourceID ="Employees" RunAt ="server"
UpdateCommand
="" OnUpdated ="OnUpdateComplete" >

asp:SqlDataSource >

voidOnUpdateComplete(Objectsource,SqlDataSourceStatusEventsArgse)
{
if(e.Exception!=null){
//Exceptionthrown.Sete.ExceptionHandledtotruetoprevent
//theSqlDataSourcefromthrowinganexception,orleaveitset
//tofalsetoallowSqlDataSourcetorethrowtheexception
}
elseif(e.AffectedRows==0){
//Noexceptionwasthrown,butnorecordswereupdated,either.
//Mightwanttolettheuserknowthattheupdatefailed
}
}



ASP.NET 2.0 綁定高級技巧


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲欧美日韩国产一区图片 | 国产福利小视频在线观看 | 玖玖在线精品 | 黄色毛片视频网站 | 国产精品高清免费网站 | 91尤物在线视频 | 亚洲欧美另类久久久精品能播放的 | 欧美午夜视频 | 婷婷综合网站 | 色视频网站在线观看 | 人人干人人模 | 99热这里只有精品国产免费 | 国产2021久久精品 | 国产不卡免费视频 | 色综合成人 | 高清欧美色欧美综合网站 | 99久久免费费视频在线观看 | 欧美乱爱 | 欧美综合图区亚洲综合图区 | 日韩中文字幕久久精品 | 91在线小视频 | 99在线视频免费观看 | 国产一区二区三区四区 | 黄色影院在线观看视频 | 又爽又黄又无遮挡的视频在线观看 | 日本一区高清视频 | 四虎影视成人永久在线观看 | 8090碰成年女人免费碰碰尤物 | 欧美日韩中文字幕在线观看 | 久久精品国产清自在天天线 | 日本老太做爰xx | 国产精品一区二区四区 | 欧美日韩免费大片 | 久久精品免视看国产盗摄 | 九九热视频在线免费观看 | 酒色网站| 香蕉成人国产精品免费看网站 | 久久精品无码一区二区日韩av | 成人在线观看不卡 | 亚洲人成网站在线观看青青 | 日本欧美在线播放 |