Posts

Showing posts from July, 2011

ASP .net material Part-7

Image
ASP.NET - Database Connection ADO.NET is also a part of the .NET Framework. ADO.NET is used to handle data access. With ADO.NET you can work with databases. What is ADO.NET? ADO.NET is a part of the .NET Framework ADO.NET consists of a set of classes used to handle data access ADO.NET is entirely based on XML ADO.NET has, unlike ADO, no Recordset object Create a Database Connection We are going to use the Northwind database in our examples. First, import the "System.Data.OleDb" namespace. We need this namespace to work with Microsoft Access and other OLE DB database providers. We will create the connection to the database in the Page_Load subroutine. We create a dbconn variable as a new OleDbConnection class with a connection string which identifies the OLE DB provider and the location of the database. Then we open the database connection: <%@ Import Namespace="System.Data.OleDb" %> <script runat="server">

ASP .net material Part-6

ASP.NET - The DataList Control The DataList control is, like the Repeater control, used to display a repeated list of items that are bound to the control. However, the DataList control adds a table around the data items by default. Bind a DataSet to a DataList Control The DataList control is, like the Repeater control, used to display a repeated list of items that are bound to the control. However, the DataList control adds a table around the data items by default. The DataList control may be bound to a database table, an XML file, or another list of items. Here we will show how to bind an XML file to a DataList control. We will use the following XML file in our examples ("cdcatalog.xml"): <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd>   <title>Empire Burlesque</title>   <artist>Bob Dylan</artist>   <country>USA</country>   <company>Columbia</company>   <p

ASP .net material Part-5

ASP.NET - The SortedList Object The SortedList object combines the features of both the ArrayList object and the Hashtable object. The SortedList Object The SortedList object contains items in key/value pairs. A SortedList object automatically sort the items in alphabetic or numeric order. Items are added to the SortedList with the Add() method. A SortedList can be sized to its final size with the TrimToSize() method. The following code creates a SortedList named mycountries and four elements are added: <script runat="server"> sub Page_Load if Not Page.IsPostBack then   dim mycountries=New SortedList   mycountries.Add("N","Norway")   mycountries.Add("S","Sweden")   mycountries.Add("F","France")   mycountries.Add("I","Italy") end if end sub </script> Data Binding A SortedList object may automatically generate the text and values to the following controls: asp:Rad

ASP .net material Part-4

ASP.NET - Data Binding We may use data binding to fill lists with selectable items from an imported data source, like a database, an XML file, or a script. Data Binding The following controls are list controls which support data binding: asp:RadioButtonList asp:CheckBoxList asp:DropDownList asp:Listbox The selectable items in each of the above controls are usually defined by one or more asp:ListItem controls, like this: <html> <body> <form runat="server"> <asp:RadioButtonList id="countrylist" runat="server"> <asp:ListItem value="N" text="Norway" /> <asp:ListItem value="S" text="Sweden" /> <asp:ListItem value="F" text="France" /> <asp:ListItem value="I" text="Italy" /> </asp:RadioButtonList> </form> </body> </html> However, with data binding we may use a separate source, li

ASP .net material Part-3

ASP.NET - Events An Event Handler is a subroutine that executes code for a given event. ASP.NET - Event Handlers Look at the following code: <% lbl1.Text="The date and time is " & now() %> <html> <body> <form runat="server"> <h3><asp:label id="lbl1" runat="server" /></h3> </form> </body> </html> When will the code above be executed? The answer is: "You don't know..." The Page_Load Event The Page_Load event is one of many events that ASP.NET understands. The Page_Load event is triggered when a page loads, and ASP.NET will automatically call the subroutine Page_Load, and execute the code inside it: Example <script runat="server"> Sub Page_Load lbl1.Text="The date and time is " & now() End Sub </script> <html> <body> <form runat="server"> <h3><asp:label id="lb