« Home « Chủ đề ASP.NET Features

Chủ đề : ASP.NET Features


Có 80+ tài liệu thuộc chủ đề "ASP.NET Features"

ASP.NET 4 Unleased - p 61

tailieu.vn

LISTING 12.4 ShowEmptyDataText.aspx. Page Language=”C#” %>. “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>. <html xmlns=”http://www.w3.org/1999/xhtml” >. <head id=”Head1” runat=”server”>. <title>Show Empty Data Text</title>. <form id=”form1” runat=”server”>. <asp:DetailsView id=”dtlMovies”. EmptyDataText=”<b>No Matching Record!</b>”. Runat=”server” />. <asp:SqlDataSource id=”srcMovies”. ConnectionString=”<. When you open the page in Listing 12.4, the contents of the EmptyDataText property display.. The page in Listing 12.5 illus- trates how you can use the EmptyDataTemplate to display...

ASP.NET 4 Unleased - p 62

tailieu.vn

FIGURE 12.7 Editing a record with the DetailsView control.. Updating Data with the DetailsView Control. You can use the DetailsView control to update existing database records. To update an existing record, assign the value True to the DetailsView control’s. AutoGenerateEditButton property, as illustrated in Listing 12.10 (see Figure 12.7).. LISTING 12.10 ShowUpdate.aspx. Page Language=”C#” %>. “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>. <html xmlns=”http://www.w3.org/1999/xhtml” >. <head...

ASP.NET 4 Unleased - p 63

tailieu.vn

ptg The DetailsView control in Listing 12.14 includes an AutoGenerateInsertButton prop-. After you open the page in Listing 12.14, you can click the New button to display a form for inserting a new record. When you click the Insert button, the SQL command repre- sented by the SqlDataSource control’s InsertCommand property is executed.. If you want the DetailsView control to...

ASP.NET 4 Unleased - p 64

tailieu.vn

Runat=”server” />. <asp:SqlDataSource id=”srcMovies”. ConnectionString=”<. Using the FormView Control. You can use the FormView control to do anything that you can do with the DetailsView control. Just as you can with the DetailsView control, you can use the FormView control to display, page, edit, insert, and delete database records. However, unlike the DetailsView control, the FormView control is entirely template-driven.....

ASP.NET 4 Unleased - p 66

tailieu.vn

Displaying Data with the Repeater Control. For example, the page in Listing 13.1 displays the contents of the Movies database table (see Figure 13.1).. LISTING 13.1 ShowRepeater.aspx. Page Language=”C#” %>. “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>. <html xmlns=”http://www.w3.org/1999/xhtml” >. <head id=”Head1” runat=”server”>. <style type=”text/css”>. FIGURE 13.1 Displaying data with a Repeater control.. <form id=”form1” runat=”server”>. <div class=”content”>. Runat=”server”>. <div class=”movies”>. <h1><%#Eval(“Title”) %></h1>. Eval(“Director”) %>. ConnectionString=”<....

asp.net 4 unleased - p 67

tailieu.vn

Page Language=”C#” %>. “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>. <script runat=”server”>. srcMovies.UpdateParameters[“Id”].DefaultValue = Keys[e.Item.ItemIndex].ToString();. srcMovies.DeleteParameters[“Id”].DefaultValue = Keys[e.Item.ItemIndex].ToString();. <html xmlns=”http://www.w3.org/1999/xhtml” >. <head id=”Head1” runat=”server”>. <style type=”text/css”>. <form id=”form1” runat=”server”>. <div class=”content”>. <asp:Repeater id=”rptMovies”. OnItemDataBound=”rptMovies_ItemDataBound” OnDataBinding=”rptMovies_DataBinding”>. <table class=”movies”>. <asp:TextBox id=”txtTitle”. Text=’<%#Eval(“Title”)%>’. Runat=”server” />. <asp:TextBox. id=”txtDirector”. Text=’<%#Eval(“Director”)%>’. <asp:CheckBox. id=”chkInTheaters”. Checked=’<%#Eval(“InTheaters”)%>’. <asp:LinkButton id=”lnkUpdate”. <asp:LinkButton id=”lnkDelete”. <asp:LinkButton id=”lnkInsert”. </asp:Repeater>. <asp:SqlDataSource id=”srcMovies”. ConnectionString=”<. Runat=”server”>. <asp:Parameter Name=”Id” />. <asp:Parameter Name=”Title” />. <asp:Parameter...

ASP.NET 4 Unleased - p 68

tailieu.vn

You can render the contents of a DataList control into a multicolumn table in which each data item occupies a separate table cell. Two properties modify the layout of the HTML table rendered by the DataList control:. RepeatColumns —The number of columns to display.. RepeatDirection —The direction to render the cells. For example, the page in Listing 13.8 displays the...

ASP.NET 4 Unleased - p 69

tailieu.vn

<form id=”form1” runat=”server”>. <asp:DataList id=”dlstMovies”. Runat=”server”>. <h1><%#Eval(“Title”)%></h1>. <%#Eval(“Director”) %>. <%#Eval(“InTheaters”) %>. <asp:LinkButton id=”lnkEdit”. Runat=”server” />. <asp:LinkButton id=”lnkDelete”. <asp:Label id=”lblTitle”. <asp:TextBox id=”txtTitle”. Text=’<%#Eval(“Title”)%>’. <asp:Label. id=”lblDirector”. <asp:TextBox. id=”txtDirector”. Text=’<%#Eval(“Director”)%>’. <asp:CheckBox. id=”chkInTheaters”. Checked=’<%#Eval(“InTheaters”)%>’. <asp:LinkButton id=”lnkUpdate”. <asp:LinkButton id=”lnkCancel”. </asp:DataList>. <asp:SqlDataSource. ptg id=”srcMovies”. ConnectionString=”<. <asp:Parameter Name=”Id” />. <asp:Parameter Name=”Title” />. <asp:Parameter Name=”Director” />. <asp:Parameter Name=”InTheaters” />. </asp:SqlDataSource>. The dlstMovies_Edit() method sets the EditItemIndex property of...

ASP.NET 4 Unleased - p 70

tailieu.vn

In Listing 14.1, the ItemTemplate renders a. If it is present, every other item displayed by the ListView control is rendered with the AlternatingItemTemplate . In Listing 14.1, the AlternatingItemTemplate is used to give alternating items a silver background color.. In Listing 14.1, the EmptyDataTemplate is used to display the text No Records Found when no items are returned from...

ASP.NET 4 Unleased - p 72

tailieu.vn

Page Language=”C#” %>. “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>. <script runat=”server”>. <html xmlns=”http://www.w3.org/1999/xhtml”>. <head id=”Head1” runat=”server”>. <form id=”form1” runat=”server”>. <asp:ListView ID=”lstMovies”. runat=”server”>. <asp:DataPager id=”pg”. Runat=”server”>. <asp:TemplatePagerField. OnPagerCommand=”pg_PagerCommand”>. <asp:LinkButton id=”lnkPrevious”. Runat=”server” />. <asp:LinkButton id=”lnkNext”. </asp:TemplatePagerField>. </asp:DataPager>. Eval(“Title”) %>. </asp:ListView>. <asp:SqlDataSource id=”srcMovies”. ConnectionString=’<. Page Language=”C#” Trace=”true” %>. <head runat=”server”>. <asp:NumericPagerField />. <asp:LinqDataSource id=”srcMovies”. Using the Chart Control . Namespace=”System.Web.UI.DataVisualization.Charting” TagPrefix=”asp” %>. “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>. <html xmlns=”http://www.w3.org/1999/xhtml” >. <asp:Chart ID=”chtMovies”...

ASP.NET 4 Unleased - p 71

tailieu.vn

Listing 15.3 sorts the movie categories from highest count to lowest count by executing the. chtMovies_DataBound method after it binds to the SqlDataSource (see Figure 15.3).. ptg FIGURE 15.3 Sorting a chart.. LISTING 15.3 SortChart.aspx. Page Language=”C#” %>. TagPrefix=”asp” %>. “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>. <script runat=”server”>. <html xmlns=”http://www.w3.org/1999/xhtml”>. <head id=”Head1” runat=”server”>. <form id=”form1” runat=”server”>. FIGURE 15.4 Filtering chart data.. <asp:Chart ID=”chtMovies” runat=”server” DataSourceID=”srcMovies”....

ASP.NET 4 Unleased - p 74

tailieu.vn

The Forecasting formula used in Listing 15.7 uses a parameter set of RegressionType, Period, ApproxError, ForecastError that enables you to optionally customize how the analysis is performed.. With ASP.NET 4, all that functionality is not only available, but also it is available in an easily accessible, easy to use API.. Customizing a Chart’s Appearance. The Chart control enables you to...

ASP.NET 4 Unleased - p 75

tailieu.vn

And you might define a static method in the page (though we recommend explicitly defining the type name so you can avoid filling your code-behinds with additional logic) as follows:. (This is another reason we recommended specifying the type name of the expression class explicitly rather than putting the expression method in the page’s code-behind.). The two properties of the...

ASP.NET 4 Unleased - p 76

tailieu.vn

In the Page_Load() event handler, an instance of the HelloWorld component is created.. Next, the result returned by a call to the SayMessage() method is assigned to a Label control. When you open the page in your browser, you see the message Hello World. This process of creating the component is simple. You are not required to explicitly compile (build)...

ASP.NET 4 Unleased - p 77

tailieu.vn

ptg LISTING 17.11 Quote.cs. using System.Collections.Generic;. public class Quote. _quotes.Add(“The only good is knowledge and the only evil is ignorance. The collection named _quotes is declared in the body of the class. That way, you can refer to the _quotes field in both the constructor and the GetQuote() method.. You can create static constructors by using the static keyword when...

ASP.NET 4 Unleased - p 78

tailieu.vn

Internal—An internal class, method, or property can be accessed only by a compo-. nent within the same assembly (dll file). Because ASP.NET pages are compiled into different assemblies than the contents of the App_Code folder, you cannot access an internal member of a class outside of the App_Code folder.. Private—A private class, method, or property can be accessed only within...

ASP.NET 4 Unleased - p 79

tailieu.vn

Adding an Assembly to the Global Assembly Cache. All the assemblies that make up the .NET Framework class library are contained in the Global Assembly Cache. For example, the Random class is located in the System.dll assem- bly, and the System.dll assembly is contained in the Global Assembly Cache. Any assem- bly located in the Global Assembly Cache can be...

ASP.NET 4 Unleased - p 80

tailieu.vn

<param name=”id”>Product Id</param>. properties to the database. throw new ArgumentException(“Product Name not supplied”, “name”);. if (_name.Length >. throw new ArgumentException(“Product Name must be less than 50 characters”, “name”);. <param name=”name”>Product Name</param>. <param name=”price”>Product Price</param>. <param name=”description”>Product Description</param>. All four of these methods use the SqlDataAccessLayer compo- nent to interact with the Products database table. The SqlDataAccessLayer is contained in the...

ASP.NET 4 Unleased - p 81

tailieu.vn

ptg In Listing 18.2, the ObjectDataSource control includes two properties named TypeName. The TypeName property contains the name of the component that you want to represent with the ObjectDataSource control. The SelectMethod property repre- sents the method of the component that you want to call when selecting data.. The GridView control is bound to the ObjectDataSource control through its DataSourceID...

ASP.NET 4 Unleased - p 82

tailieu.vn

cmd.Connection = con;. cmd.CommandText = “UPDATE Movies SET Title=@Title,Director=@Director,DateReleased=. cmd.Parameters.AddWithValue(“@Title”, title);. cmd.Parameters.AddWithValue(“@Director”, director);. cmd.Parameters.AddWithValue(“@DateReleased”, dateReleased);. cmd.Parameters.AddWithValue(“@Id”, id);. cmd.ExecuteNonQuery();. cmd.CommandText = “SELECT Id,Title,Director,DateReleased FROM Movies”;. return cmd.ExecuteReader(CommandBehavior.CloseConnection);. The page in Listing 18.12 contains a GridView and ObjectDataSource control. The ObjectDataSource control includes an UpdateMethod property that points to the UpdateMovie() method.. LISTING 18.12 ShowMovies.aspx. Page Language=”C#” %>. “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>. <html xmlns=”http://www.w3.org/1999/xhtml” >....