Database Reference
In-Depth Information
How It Works
First, you verify whether you have a successful log.
if (txtUserName.Text == "agarwal")
Once this condition is true, you want the user to be able to automatically navigate to WebDataForm.
For this purpose, you used ASP.NET's Response object and its Redirect function, which takes the page
name you would like to redirect to.
Response.Redirect("WebDataForm.aspx");
In the event of incorrect login, we are also showing an error message to the user. To show this error,
we used Response object's Write method, which takes the string that you want to display on the page.
Response.Write("Invalid User Name, please try again!");
Using the Repeater Control
The Repeater control is an ASP.NET-specific control; in other words, it doesn't exist in Windows Forms.
The Repeater control serves the purpose of a container control, which allows you to create custom lists
to present data on the web page. Another feature of the Repeater control is that it does not have a built-
in rendering of its own, which means that a web developer must provide the layout for the Repeater
control with the help of templates. The Repeater control is capable of using various type of templates,
such as ItemTemplate, HeaderTemplate, SeperatorTemplate, and FooterTemplate.
When the web page loads with a Repeater control, the Repeater control iterates through the data
rows in the data source and renders data for each record found.
Unlike ListBox, GridView, TextBox, and so on, which you have used with database in earlier
chapters, the Repeater control has no default look; hence, it makes it very flexible and powerful to be
used with any type of lists, including a table layout, a comma-delimited list, or an XML-formatted list.
Now you have half the application ready and working, as shown in Figure 16-8. The next task will be
to add functionality to WebDataForm; for this purpose, you will use one of the ASP.NET-specific data
controls called the Repeater control, as discussed earlier.
Try It: Working with Repeater Control
In this exercise, you will add a Repeater control to a web form, and then you will write the required
functionality to populate it with the data from a database.
1. Navigate to Solution Explorer. Right-click the WebDataForm.aspx web form, and
select the View Designer option; this will open the WebDataForm.aspx page in
the Design view, where you can drag and drop controls onto the web page.
2. Navigate to the Toolbox, expand the Data tab, and then drag a Repeater
control to WebDataForm.aspx , positioning it toward the top left of the form.
3. Now press F4 to open the Properties window. Select the Repeater control,
navigate to the Properties window, and set the Id property to RepData. Your
WebDataForm will now look like Figure 16-9.
 
Search WWH ::




Custom Search