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

Extended GridView with Insert Functionality

Rate me:
Please Sign up or sign in to vote.
4.96/5 (35 votes)
26 Oct 2007CPOL8 min read 307.2K   3.7K   130  
An extended GridView that adds inserting to its capabilities plus a number of other enhancements
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="TestWeb.DefaultPage" %>
<%@ Register Assembly="TestWeb" Namespace="TestWeb" TagPrefix="Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>ExtendedGridView demo</title>
</head>
<body>
	<form id="theForm" runat="server">
		<Test:ExtendedGridView ID="extendedGrid" runat="server" AllowInserting=True DataSourceID="dataSource" DataKeyNames="Id" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" AscendingImageUrl="~/SortAsc.gif" BorderColor="Silver" CellPadding="4" DescendingImageUrl="~/SortDesc.gif" ForeColor="#333333" PageSize="3" ShowResultSummary="True" Width="400px" >
			<PagerSettings Position="topAndBottom" />
			<Columns>
				<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
				<asp:BoundField DataField="StockLevel" HeaderText="Stock Level" SortExpression="StockLevel" />
				<Test:ExtendedCommandField HeaderText="Action" ShowHeader="True" ShowInsertButton="True" ShowDeleteButton="True" ShowEditButton="True" DeleteConfirmationText="Are you sure?" />
			</Columns>
			<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
			<RowStyle BackColor="#EFF3FB" />
			<EditRowStyle BackColor="#FFFFAA" />
			<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
			<PagerStyle HorizontalAlign="Center" />
			<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
			<AlternatingRowStyle BackColor="White" />
		</Test:ExtendedGridView>
		<asp:ObjectDataSource ID="dataSource" runat="server" DeleteMethod="Delete" InsertMethod="Insert" SelectMethod="GetData" TypeName="TestWeb.SomeData"
			UpdateMethod="Update">
			<DeleteParameters>
				<asp:Parameter Name="id" Type="Int32" />
			</DeleteParameters>
			<UpdateParameters>
				<asp:Parameter Name="id" Type="Int32" />
				<asp:Parameter Name="name" Type="String" />
				<asp:Parameter Name="stockLevel" Type="Int32" />
			</UpdateParameters>
			<InsertParameters>
				<asp:Parameter Name="name" Type="String" />
				<asp:Parameter Name="stockLevel" Type="Int32" />
			</InsertParameters>
		</asp:ObjectDataSource>
	</form>
</body>
</html>

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 Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions