惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
WordPress大学
WordPress大学
Help Net Security
Help Net Security
Jina AI
Jina AI
Security Latest
Security Latest
Y
Y Combinator Blog
Project Zero
Project Zero
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
Know Your Adversary
Know Your Adversary
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
博客园 - 司徒正美
MyScale Blog
MyScale Blog
Cyberwarzone
Cyberwarzone
D
Docker
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
C
CERT Recently Published Vulnerability Notes
B
Blog
L
LangChain Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
The Hacker News
The Hacker News
C
Check Point Blog
L
Lohrmann on Cybersecurity
V2EX - 技术
V2EX - 技术
S
Securelist
T
Threat Research - Cisco Blogs
Stack Overflow Blog
Stack Overflow Blog
TaoSecurity Blog
TaoSecurity Blog
云风的 BLOG
云风的 BLOG
Latest news
Latest news
人人都是产品经理
人人都是产品经理
L
LINUX DO - 最新话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Register - Security
The Register - Security
Webroot Blog
Webroot Blog
Simon Willison's Weblog
Simon Willison's Weblog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
AWS News Blog
AWS News Blog
C
Cybersecurity and Infrastructure Security Agency CISA
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
小众软件
小众软件
T
Tailwind CSS Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
宝玉的分享
宝玉的分享
O
OpenAI News

博客园 - 深瞳

懒惰化、标准化、自动化——工具化--利用合适的工具构建流水线软件过程 脚本语言的游戏开发 准妈妈必听的十首乐曲完全版 [原创]Flex和PHP脚本的整合(2)--AMFPHP篇 [原创]Flex和PHP脚本的整合(1)--XML篇 夜如深瞳,瞳深如夜 新一波VB.NET升级需求涌现 使用VS2005的WEB部署工程 VS2005web应用程序项目教程(7)Upgrading VS 2003 Web Projects to be VS 2005 Web Application Projects VS2005web应用程序项目教程(6)Creating and Using User Control Libraries VS2005web应用程序项目教程(5)Using Master Pages and Site Navigation VS2005web应用程序项目教程(3)Building Pages with VS 2005 Web Application Projects VS2005web应用程序项目教程(2)Code-Behind with VS 2005 Web Application Projects VS2005web应用程序项目教程(1)Building Your First Web Application Project 在.net开发中几个重要的认识误区 CSVS 和CSSDK 的区别 ASP.net(1.1)原理学习笔记--第十一章 安全性Security ASP.net(1.1)原理学习笔记--第十章 状态管理State Management ASP.net(1.1)原理学习笔记--第九章 缓存Caching
VS2005web应用程序项目教程(4)Data Binding against Objects
深瞳 · 2006-01-31 · via 博客园 - 深瞳

Tutorial 4: Data Binding against Objects

The below tutorial demonstrates how to build ASP.NET Pages that databind against Objects within VS 2005 Web Application Projects. Please make sure that you have already completed Tutorial 3: Building Pages with VS 2005 Web Application Projects before reviewing this one.

Adding Classes to the Web Project

In this sample we'll be data-binding a GridView control on a page to a set of classes in our web application project.

To begin, right-click on the project and select Add->Add New Item to add a new class called "Author" to the project:

Note that classes can be added into any directory of the web project. There is no requirement that they live under the /app_code directory.

Make the new Author class public and then add some properties and constructors to it:

Then add a new class file called "Publisher.cs" to the project and have it implement a method called "GetAuthorsByState":

Note that the above method uses Generics (a new feature in V2.0) to return a strongly typed List collection of type "Author".

Choose either the "Build->Build Solution" menu item or choose "Ctrl-Shift-B" to build the project. You now have a set of classes you can use to databind against.

Building a Data-Bound ASP.NET Page

Right-click on the project and select Add->Add New Item to add a new ASP.NET Page called "DataSample.aspx" to the project:

Switch to design-view on the newly created DataSample.aspx page, add a simple page title, a search Textbox called "TextBox1", a button, and then drag/drop a GridView control from the "Data" section of the Toolbox:

Select "New DataSource" from the drop-downlist in the "Common Tasks" smart-tag menu. Select "Object" as the data-source you want to bind-to. This will then bring up a wizard that lists all classes in your project:

Select the "MyWebProject.Publisher" class, and then hit next. Then choose the "GetAuthorsByState" method as the method to bind against:

Choose to bind the "state" parameter of the "GetAuthorsByState" method to the TextBox1 on the page (note: change the parameter source to "control" to get this listing):

When you click "finish" the GridView columns will be updated to reflect the public properties in your Author class. Choose the "Auto format" task on the GridView control to make it look a little better:

To test the page, select the DataSample.aspx page in the solution explorer, right click, and then select the "Set as Start Page" context menu item. Then hit F5 (or ctrl-f5) to build, run and debug. When you add "wa" as the state parameter you'll get a list of authors: