![]() ![]() | ||
Say that I want to bind a text box in a Web form to a field in the authors table in the pubs database. Assuming that I have access to a server that can run Web applications and that I have a data connection to the pubs database using a data provider on that or another server, I can start the whole process just as I would in a Windows application. All I have to do is to drag a data adapter onto the Web form from the Data tab of the toolbox, use the Data Adapter Configuration Wizard to configure the data adapter to use the connection to the pubs database, and select all fields in the authors table in that database, as we have done before. Then I would use the Data|Generate Dataset menu item to create the dataset to use. That's all it takes to get a dataset ready for use in a Web form, and we haven't done anything we wouldn't have done in a Windows form.
Note |
To create data connections to databases on servers locally or on the Web, see "Creating a New Data Connection" in Chapter 20. You also can use the Server Explorer—which displays all your current data connections—for this purpose; see "Using the Server Explorer" in Chapter 20. |
And as in Windows applications, you can bind any property of any control in a Web application to a data source. To do that, you click the ellipsis ("…") button that appears when you select the control's (DataBindings) property. Doing so opens the DataBindings dialog box you see in Figure 23.1.
In Figure 23.1, I'm binding the Text property of a text box Web server control (all the controls in this chapter will be Web server controls) to the au_fname field in the pubs database's authors table—that is, to the author's first name. And that's all it takes to support simple data binding—you just use a control's (DataBindings) property as I have done here. You can bind any property of any control to a data source. Just bear in mind that you're responsible for maintaining that binding yourself, using the DataBind method, which you can call each time you want to refresh that data binding, as when the page loads.
![]() ![]() | ||