Mar
10
Written by:
Steve Gray
3/10/2011 6:04 PM
Following is an example of the ComponentArt basic grid.
Now, if you use the CA grid at all you know that they install examples right on your machine for you to learn from.
The reason that I’m coding these examples is:
- Their examples are sometimes too verbose
- Their examples aren’t coded the way that I have the grids coded – I use a class that abstracts a lot of the grid setup so that I don’t have to look at it, and so that it is consistent across a project.
These examples are coded in a master page, I’m providing only the needed details here.
So, here is a complete working example of the grid.
An on-line example is provided here: http://componentart.devshed.us/Examples/Grid/Basic.aspx
There is a reference to the ComponentArtGrid class in the code behind, that’s here: http://devshed.us/Blogs/tabid/227/EntryId/1004/ComponentArt-Grid-Class.aspx
And the style sheet is here (gridStyle.css) http://devshed.us/Blogs/tabid/227/EntryId/1005/ComponentArt-Grid-Css.aspx
The aspx page:
Code Snippet
- <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="Basic.aspx.vb" Inherits="ComponentArt.Basic" %>
- <%@ Register Assembly="ComponentArt.Web.UI" Namespace="ComponentArt.Web.UI" TagPrefix="ComponentArt" %>
- <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
- </asp:Content>
- <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
- <div >
- <span>This grid the basic grid</span><br />
- <a href="http://devshed.us/Blogs/tabid/227/EntryId/1006/ComponentArt-Grid-Editing-ndash-Client-Mode-Example.aspx" target="_blank">The code for this example is here</a><br />
-
- <br />
- <br />
- <ComponentArt:DataGrid ID="Grid1"
- runat="server">
- <Levels>
- <ComponentArt:GridLevel
- DataKeyField="lRowID"
- EditCommandClientTemplateId="EditCommandTemplate"
- InsertCommandClientTemplateId="InsertCommandTemplate"
- >
- <Columns>
- <ComponentArt:GridColumn AllowEditing="false" DataField="lRowID" Visible="false" />
- <ComponentArt:GridColumn DataField="Itemnmbr" HeadingText="Item" AllowEditing="false" />
- <ComponentArt:GridColumn DataField="Quantity" HeadingText="Quantity" />
- <ComponentArt:GridColumn DataField="UnitCost" HeadingText="Unit Cost" AllowEditing="false" />
- </Columns>
- </ComponentArt:GridLevel>
- </Levels>
- </ComponentArt:DataGrid>
-
- </asp:Content>
The Code Behind:
Code Snippet
- Public Class Basic
- Inherits System.Web.UI.Page
-
- Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- If Not IsPostBack Then
- buildGrid()
- Grid1.DataBind()
- End If
-
- End Sub
-
- Private Sub buildGrid()
- Dim grd As New ComponentArtGrid
- Grid1 = grd.setup(Me.Grid1)
- Grid1.Width = 500
-
- Dim i As New Item
- 'returns a datatable of items
- Grid1.DataSource = i.getItems
-
- End Sub
-
- End Class
As always, I welcome your comments!