




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、Walkthrough: Databinding with IronPython for ASP.NETIntroductionIronPython code is dynamically compiled, which allows simplified data binding syntax and increased flexibility. This walkthrough shows you how to add IronPython code to tailor the appearance of data retrieved from a Microsoft Access dat
2、abase (.mdb file). Note Access databases do not have the same capacity and are not as scalable as other types of databases, such as Microsoft SQL Server. This walkthrough uses an Access database because the Northwind.mdb sample database is widely known and available. Generally, if y
3、ou are creating a Web site that will support only light traffic or a limited number of users, you should use a SQL Server Express database. However, if the Web site will support more throughput or a larger number of users, you should consider using SQL Server or another database that is suited for p
4、roduction Web sites.PrerequisitesIn order to complete this walkthrough, you will need the following: · Microsoft Visual Studio 2005 or Microsoft Visual Web Developer· IronPython for ASP.NET Community Technology Preview, including Visual Studio Integration or Visual Web Developer Integratio
5、n, as appropriate· The Northwind.mdb file that contains the Access version of the sample Northwind database. Alternatively, you can use another database and adjust the steps in the walkthrough to match the database and tables that you are using.This walkthrough assumes that you have a general u
6、nderstanding of working with ASP.NET in Visual Studio, and a general knowledge of data binding in ASP.NET. For an introduction to ASP.NET in Visual Studio, see Walkthrough: Creating a Basic Page in Visual Web Developer. For an introduction to data binding in ASP.NET, see "Data-Driven Web Pages&
7、quot;.Creating the Web Site and PageIf you have already created a Web site in Visual Studio (for example, by working with the companion walkthrough "Creating a Basic Web Page with IronPython"), you can use that Web site and go to the next part of the walkthrough, where you add an Access da
8、tabase to the project. Otherwise, create a new Web site and page by following these steps.To create a file system Web site1. Open Visual Studio or Visual Web Developer.2. On the File menu, click New Web Site.The New Web Site dialog box appears. 3. In the Language list, click IronPython to make IronP
9、ython the default language for the Web site. Note You can use statically compiled languages in the same Web application by creating pages and components in different programming languages.4. Under Visual Studio installed templates, click ASP.NET Web Site.5. In the Location box, sele
10、ct the File System box, and then enter the name of the folder where you want to keep the pages of your Web site. For example, type the folder name C:DatabaseWebSite.6. Click OK. Visual Studio creates the folder and a new page named Default.aspx.Next you will add the Northwind.mdb Access database or
11、your own database to the Web application project.To add an Access database to the project1. If the App_Data folder does not exist in Solution Explorer, right-click the name of your Web site, click Add ASP.NET Folder, and then click App_Data.2. In Visual Studio, in Solution Explorer, right-click the
12、App_Data folder, and then click Add Existing Item.3. Use the Add Existing Item dialog to locate the Northwind.mdb file (or other .mdb or .mdf file) that you want to use for this walkthrough, and then click Add to add it to your application.This walkthrough does not configure permissions for the Acce
13、ss database. For information on configuring permissions for an Access database, see the MSDN Online Library topic "Walkthrough: Creating a Web Page to Display Access Database Data".Using Access Data on an ASP.NET Web PageYou can now use the database in a Web page. This part of the walkthro
14、ugh uses an AccessDataSource control and a DataList control.To add AccessDataSource and DataList controls to the page1. Open the Default.aspx page (or another page that you want to use) and switch to Design view.2. From the Data group in the Toolbox, drag an AccessDataSource control onto the page.No
15、te If the Access Data Source Tasks shortcut menu does not appear, right-click the control and then click Show Smart Tag.3. On the Access Data Source Tasks shortcut menu, click Configure Data Source.The Configure Data Source wizard appears.4. On the Choose a database page, in the Mic
16、rosoft Access Data file box, type /App_Data/Northwind.mdb or use the Browse button to select the .mdb file. 5. Click Next to open the Configure Select Statement page, and click Specify columns from a table or view.6. In the Name list, click Categories.7. Select the CategoryName and Description check
17、 boxes and click Next.8. Optionally, click Test Query to test your query.9. Click Finish.10. From the Data group in the Toolbox, drag a DataList control onto the page.11. On the DataList Tasks menu, in the Choose Data Source box, click AccessDataSource1.12. Click Ctrl+F5 to run the page with the def
18、ault layout.13. Close the browser.Working with IronPython Code in the DataList ControlIn this part of the walkthrough you will use IronPython code to perform data binding, rather than using the Eval method that is generated by default for declarative data binding.To use IronPython code in the DataLi
19、st1. Switch to Source view, and remove the Eval methods from DataList1. When you are finished, the DataList control markup will look like the following:<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1"> <ItemTemplate> CategoryName:
20、 <asp:Label ID="CategoryNameLabel" runat="server" Text='<%# CategoryName %>'> </asp:Label><br /> Description: <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Description %>'> </asp:Label><b
21、r /> <br /> </ItemTemplate></asp:DataList>The data bindings are now simply IronPython code. Because IronPython is a dynamic language, the field names can be resolved using late binding.2. Click Ctrl+F5 to run the page, and verify that the page looks the same.3. Close the browser
22、.Because the bindings are IronPython code, you can use them to change the way the field values are displayed. In this part of the walkthrough, you will change the case of the CategoryName field, and change the background color of the Description field depending on the length of the CategoryName fiel
23、d.To use IronPython code to change the appearance of fields1. Switch to the code for the page, and add the following import statement:from System.Drawing import Color2. Add the following function to return a color based on the size of a string:def ColorPicker(input): input = str(input) if len(input)
24、 > 10: return Color.Yellow else: return Color.White3. Return to the Web page markup, replace the text "CategoryName:" with the text "The <%# CategoryName.upper() %> category includes:", and remove the CategoryNameLabel label from the item template. When you are finished,
25、 the item template will look like the following.<ItemTemplate> The <%# CategoryName.upper() %> category includes: Description: <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Description %>'> </asp:Label><br /> <br /><
26、;/ItemTemplate>IronPython will resolve the field name and apply the upper() method to the field. Be sure to include the parentheses; if you omit them, IronPython returns an object representing the method itself, which will not display anything. Note You can use either the Python
27、upper method or the .NET Framework ToUpper method.4. Remove the text "Description:" above the DescriptionLabel label, and add a BackColor attribute to the DescriptionLabel label.When you are finished, the item template will look like the following.<ItemTemplate> The <%# CategoryName.upper() %> category includes: <asp:Label ID="Descripti
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年高中化學新教材同步 必修第一冊 第3章 第2節(jié) 實驗活動2 鐵及其化合物的性質(zhì)
- 【四川卷】四川省德陽市高中2022級(2025屆)高三質(zhì)量監(jiān)測考試(二)(德陽二診)(2.21-2.23)英語試卷答案
- 傾廢航行數(shù)據(jù)記錄儀戰(zhàn)略市場規(guī)劃報告
- 鎳精礦戰(zhàn)略市場規(guī)劃報告
- 信鴿教練合同范本
- 加盟 轉(zhuǎn)讓合同范本
- 值守合同范本
- 中國學生發(fā)展核心素養(yǎng)心得體會
- 臺車出售合同范本
- 水利工程師水力學試題(附參考答案)
- 切爾諾貝利核電站事故工程倫理分析
- 汽車網(wǎng)絡安全運營中心(VSOC)白皮書-2023.09
- 大灰狼兒童睡前故事大全
- 部編版六年級下冊語文文言文二則《學弈》說課課件
- +消除誤解 心理健康課件
- 會計人才培養(yǎng)方案調(diào)研報告書
- 企業(yè)標準自我聲明公開
- 高考英語備考-英語單詞構(gòu)詞法詞根和詞綴課件
- 中公中學教育知識與能力(對應中公教材)課件
- 電動托盤車(搬運車)培訓-課件
- 格律詩基礎(chǔ)知識教學課件
評論
0/150
提交評論