Click here to Skip to main content
15,881,613 members
Articles / Web Development / ASP.NET

Manage ViewState Using ASP.NET 2.0 Provider Architecture

Rate me:
Please Sign up or sign in to vote.
3.93/5 (5 votes)
5 Jun 2007CPOL7 min read 78.2K   752   49  
Serverside ViewState management using custom providers based on ASP.NET 2.0 provider pattern architecture.
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="SimpleGrid.ascx.vb" Inherits="ViewStateStorageExamples.SimpleGrid" %>

<asp:DataGrid id="EmployeeGrid" runat="server"
	BorderColor="#999999" 
	BorderStyle="None" 
	BorderWidth="1px" 
	BackColor="White"
	CellPadding="3" 
	GridLines="Vertical" 
	Font-Names="Arial" 
	AutoGenerateColumns="False" 
	Width="100%" 
	AllowPaging="true"
	AllowSorting="true"
	PageSize="5"
	DataKeyField="EmployeeID"
	OnEditCommand="EmployeeGrid_EditCommand" 
	OnUpdateCommand="EmployeeGrid_UpdateCommand"
	OnCancelCommand="EmployeeGrid_CancelCommand" 
	OnDeleteCommand="EmployeeGrid_DeleteCommand" 
	OnSortCommand="EmployeeGrid_SortCommand"
	OnPageIndexChanged="EmployeeGrid_PageIndexChanged" >
	<FooterStyle ForeColor="Black" BackColor="#CCCCCC" />
	<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C" />
	<AlternatingItemStyle BackColor="Gainsboro" />
	<ItemStyle ForeColor="Black" BackColor="#EEEEEE" />
	<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084" />
	<Columns>
		<asp:TemplateColumn HeaderText="Name" SortExpression="LastName" >
			<ItemStyle Width="10%" />
			<ItemTemplate>
				<%# DataBinder.Eval(Container, "DataItem.TitleOfCourtesy") + " " + DataBinder.Eval(Container, "DataItem.LastName") + ", " + DataBinder.Eval(Container, "DataItem.FirstName") %>
			</ItemTemplate>
		</asp:TemplateColumn>
		<asp:TemplateColumn HeaderText="Address">
			<ItemStyle Width="10%" />
			<ItemTemplate>
				<%# DataBinder.Eval(Container, "DataItem.Address") %>
			</ItemTemplate>
			<EditItemTemplate>
				<asp:TextBox ID="Address" Text='<%# DataBinder.Eval(Container, "DataItem.Address") %>' Runat="server" />
			</EditItemTemplate>
		</asp:TemplateColumn>
		<asp:BoundColumn DataField="City" ReadOnly="False" HeaderText="City" SortExpression="City" ItemStyle-Width="5%" />
		<asp:BoundColumn DataField="Region" ReadOnly="False" HeaderText="Region" SortExpression="Region" ItemStyle-Width="2%"/>
		<asp:BoundColumn DataField="PostalCode" ReadOnly="False" HeaderText="Postal Code" SortExpression="PostalCode" ItemStyle-Width="5%" />
		<asp:BoundColumn DataField="Country" ReadOnly="False" HeaderText="Country" SortExpression="Country" ItemStyle-Width="3%" />
		<asp:BoundColumn DataField="HomePhone" ReadOnly="False" HeaderText="Home Phone" SortExpression="HomePhone" ItemStyle-Width="5%" />
		<asp:TemplateColumn HeaderText="Notes">
			<ItemStyle Width="40%" />
			<ItemTemplate>
				<div style="height: 50px; overflow: auto;" >
					<%#DataBinder.Eval(Container, "DataItem.Notes")%>
				</div>
			</ItemTemplate>
			<EditItemTemplate>
				<asp:TextBox ID="Notes" Text='<%# DataBinder.Eval(Container, "DataItem.Notes") %>' Runat="server" />
			</EditItemTemplate>
		</asp:TemplateColumn>
		<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit" 
			ItemStyle-Width="15%" />
		<asp:ButtonColumn Text="Delete" ButtonType="PushButton" CommandName="Delete" ItemStyle-Width="5%" />
	</Columns>
	<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages" />
</asp:DataGrid>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Oleg Sobol has been developing web applications in ASP.NET using VB.NET for the past three years. Currently working for a leading online higher education provider, developing new online initiatives and supporting multiple education platforms.

Comments and Discussions