Thursday, June 28, 2007

Strongly Typed DataSets over UnTyped DataSets

A typed DataSet is a class that derives from a DataSet.

You can access tables and columns by name, instead of using collection-based methods. A typed DataSet also allows the Visual Studio .NET code editor to automatically complete lines as you type.

The strongly typed DataSet provides access to values as the correct type at compile time. With a strongly typed DataSet, type mismatch errors are caught when the code is compiled rather than at run.

Typed Datasets increase the readability as we are no more using the ordinal index of the columns and it doesn't depend on the changes done in the backyard.

The typed DataSet code is shorter, requires neither the table name nor the column name to be accessed via a string or ordinal position, and it does not require the Rows property. You can use IntelliSense to get a list of the table names available to the typed DataSet as well as a list of the column names available to its tables, so the code is really easy to write. In the typed DataSet, the columns are all defined as properties with their respective datatypes. . Typed DataSets make binding to controls easier since they contain the schema information within them. When binding a typed DataSet to an ASP.NET DataGrid, the properties menu reads the selected typed DataSet's schema and recognizes the DataTables and the DataColumns that the typed DataSet exposes. The Properties window fills the DataMember list with the names of the selected DataSet's DataTable objects. Likewise, the list of available fields is loaded into the DataKeyField property.

There are differences in maintenance and performance when referring to columns in an untyped DataSet. The strongly typed DataSet offers advantages over the untyped DataSet in terms of speed and easy maintainability.

Classes

It takes an XML Schema Definition (XSD) file as well as a class file to create a strongly typed DataSet. The XSD file stores the XML that defines the schema for the strongly typed DataSet.

A strongly typed DataSet is actually a class that inherits from the System.Data.DataSet class and adds a few extra features of its own. The class file is generated from the XSD file. You can regenerate the class file by right-clicking in the XSD's designer view and selecting Generate DataSet (alternatively, you can use the xsd.exe command-line utility). The class file actually contains a series of classes that inherit from and extend the DataSet, DataTable, DataRow, and EventArgs classes. Because of this inheritance, developers do not lose any functionality by using a strongly typed DataSet. For example, even though you can refer to a DataTable via a property with the same name as the table, you can still refer to the table through the Tables collection. So, oDS.Tables["Orders"] is same as the oDS.Orders.

The strongly typed DataSet class file contains one class that inherits from the base DataSet. It also contains one class for every DataTable contained within the DataSet. For example, if there are both Orders and OrderDetails DataTables in a strongly typed DataSet, there will be classes called OrdersDataTable and OrderDetailsDataTable that both inherit from the DataTable object. Likewise, there would be classes named OrdersRow and OrderDetailsRow that inherit from DataRow. Because of this inheritance, these classes also expose all of the standard functionality that the base classes expo

Strongly typed DataSets also offer a few additional methods to extend the DataSet base class. For example, a typed DataSet based on the Northwind database's Orders table would expose the method FindByOrderID which would accept an integer argument that would locate the DataRow with the corresponding OrderID value. The standard Find method could still be used since all of the base class's method and properties are available, but the extended properties and methods can make writing code a bit easier on developers.

Strongly typed DataSet objects are practically self documenting since they are so easy to read. Because the names of the tables and columns that they represent are properties of the typed DataSet class, writing code with typed DataSets is more intuitive and easier to maintain. By making development time faster, easier, less prone to typing errors, and by making the code more maintainable, strongly typed DataSets are a great help to developers who want to write more effective code more efficiently.

Tuesday, June 26, 2007

Creating Tab Strip using Multi-View and View Server Controls


Here is a very simple way to create a Tab Strip display for tabbed user interface using existing ASP .NET Server controls viz., Multi-View and View Server Controls.

This code creates an illusion of tab-strip control in asp .net. On click event of the Menu Control, it changes the 'View' that are part of the Multi-View control. So, presumably this causes a postback of the page. You can prevent this using UpdatePanel of ASP .NET AJAX toolkit and setting the trigger on Menu Control click.

You can use the following code into any ASPX file and see the output as is shown here in the pretty screen shot.



<table border="0" cellpadding="0" cellspacing="0">



<tr id="menustrip">

<td>

<asp:Menu ID="mnuTabs" runat="server" Orientation="Horizontal" BackColor="#B5C7DE" DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="1em" ForeColor="#284E98" StaticSubMenuIndent="10px" OnMenuItemClick="mnuTabs_MenuItemClick">

<Items>

<asp:MenuItem Text="Tab 1" Value="1" Selected="True"></asp:MenuItem>

<asp:MenuItem Text="Tab 2" Value="2"></asp:MenuItem>

<asp:MenuItem Text="Tab 3" Value="3"></asp:MenuItem>

<asp:MenuItem Text="Tab 4" Value="4"></asp:MenuItem>

</Items>



<StaticMenuItemStyle HorizontalPadding="10px" VerticalPadding="4px" ItemSpacing="0" BorderColor="#507cd1" BorderStyle="dotted" BorderWidth="1" />

<DynamicHoverStyle BackColor="#284E98" ForeColor="White" />

<DynamicMenuStyle BackColor="#B5C7DE" />

<StaticSelectedStyle BackColor="#507CD1" ForeColor="White" BorderColor="#507cd1" BorderStyle="solid" BorderWidth="1" />

<DynamicSelectedStyle BackColor="#507CD1" />

<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />

<StaticHoverStyle BackColor="#284E98" ForeColor="White" />

</asp:Menu>



</td>

<td></td>

</tr>

<tr>

<td colspan="2">

<div style="border: solid 2px #507cd1; border-top-width:4px; display:table; position:relative; padding: 3px 5px 3px 5px; min-width:975px; min-height:200px;">

<asp:MultiView ID="mvwPanes" runat="server">

<asp:View ID="View1" runat="server">

<p class="tab-view-heading">

Pane 1</p>

</asp:View>

<asp:View ID="View2" runat="server">

<p class="tab-view-heading">

Pane 2</p>

</asp:View>

<asp:View ID="View3" runat="server">

<p class="tab-view-heading">

Pane 3</p>

</asp:View>

<asp:View ID="View4" runat="server">

<p class="tab-view-heading">

Pane 4</p>

</asp:View>

</asp:MultiView>

</div>

</td>

</tr>

<tr id="viewstrip">



</tr>

</table>

 
Dotster Domain Registration Special Offer