Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Jan 12

Written by: Steve Gray
1/12/2011 10:35 AM  RssIcon

When you start a new project, it takes a little time to get the ComponentArt Grid setup. A little more for me, because I use a class to abstract some of the grid setup (it keeps the code cleaner, and the project more consistent).

So, here is the template that I copy into most projects to make things simpler for me.

We’ll need:

  • The .css file
  • The images folder
  • The grid class
  • The template aspx page, and the code behind.

I’ll not put the images here, you can get that from the ComponentArt sample code.

CSS:

Code Snippet
  1. .EditField {   font-family: verdana;
  2.   font-size: 10px;
  3. }
  4. .Grid
  5. {
  6.   border: 1px solid #57566F;
  7.   border-bottom: 2px solid #57566F;
  8.   background-color: #FFFFFF;
  9.   cursor: pointer;
  10.     margin: 0 auto;
  11. }
  12.  
  13. /* main style for parent and child rows*/
  14. .Row
  15. {
  16.   background-color: #ffffff; height:18px
  17. }
  18. .Row td.DataCell
  19. {
  20.   padding: 3px;
  21.   padding-top: 2px;
  22.   padding-bottom: 1px;
  23.   border-bottom: 1px solid #EAE9E1;
  24.   font-family: verdana;
  25.   font-size: 10px;
  26. }
  27.  
  28. .Row2
  29. {
  30.   background-color: #a9c7f4;
  31. }
  32. .Row2 td.DataCell
  33. {
  34.   padding: 3px;
  35.   padding-top: 2px;
  36.   padding-bottom: 1px;
  37.   border-bottom: 1px solid #EAE9E1;
  38.   font-family: verdana;
  39.   font-size: 10px;
  40. }
  41. .RedRow
  42. {
  43.     color:Red;
  44.     }
  45. /*handle the selected row. Copy from 'row', and edit*/
  46.  
  47. .SelectedRow
  48. { BACKGROUND-COLOR: #90a8d0;
  49.   height:18px
  50. }
  51. .SelectedRow td.DataCell
  52. {
  53.   padding: 3px;
  54.   padding-top: 2px;
  55.   padding-bottom: 1px;
  56.   border-bottom: 1px solid #EAE9E1;
  57.   font-family: verdana;
  58.   font-size: 10px;
  59. }
  60.  
  61. .HeadingRowFlat
  62. {  background-color: #0865ce;
  63. }
  64. .HeadingRow
  65. {  
  66.     background-image: url(/images/menuBg.jpg);
  67.     height:20px
  68. }
  69. .HeadingCell
  70. {
  71.   color:white;
  72.   padding: 3px;
  73.   padding-top: 0px;
  74.   padding-bottom: 0px;  
  75.   height:4px; padding-left:6px
  76. }
  77. .HeadingCellHover
  78. {
  79.     background-image: url(/images/menuBg.jpg);
  80. }
  81.  
  82. .HeadingCellActive
  83. {
  84.   background-color: #F6F6F7;  
  85. }
  86.  
  87. .HeadingRow td.FirstHeadingCell
  88. {
  89.   background-image: url(/images/menuBg.jpg);
  90. }
  91.  
  92. .HeadingCellText
  93. {
  94.   font-family: verdana;
  95.   font-size: 10px;
  96.   font-weight: bold;
  97.   text-align: left;
  98.   padding-top: 0px;
  99.   padding-bottom: 0px;
  100. }
  101.  
  102.  
  103.  
  104. .HeadingCell2
  105. {
  106.   background-image: url(/images/menuBg3.jpg);
  107.   color:white;
  108.   padding: 3px;
  109.   padding-top: 2px;
  110.   padding-bottom: 2px;  height:4px; padding-left:6px
  111. }
  112. .HeadingRow2
  113. {  background-image: url(/images/menuBg3.jpg);
  114.     height:40px;
  115. }
  116.  
  117.  
  118.  
  119.  
  120. .GridHeader
  121. {
  122.   background-image: url(/images/menuBg.jpg);
  123.   background-color: #8988A5;
  124.   border-bottom: 1px solid #57566F;
  125.   height: 28px;
  126.   padding-left: 3px;
  127.   cursor: default;
  128.   color: #FFFFFF;  
  129.   font-family: verdana;
  130.   font-size: 10px;
  131.   font-weight: bold;
  132.   vertical-align: middle;
  133.     
  134.     }
  135.  
  136. .GridHeaderText
  137. {
  138.   color: green;
  139.   font-family: verdana;
  140.   font-size: 10px;
  141. }
  142.  
  143. /*used for slider grids*/
  144. .GridFooter
  145. {
  146.   cursor: default;
  147.   padding: 5px;
  148.   height: 45px;
  149.   vertical-align: bottom;
  150. }
  151. /*used for non slider grids*/
  152. .GridFooter2
  153. {
  154.   cursor: default;
  155.   padding: 5px;
  156.   height: 20px;
  157.   vertical-align: bottom;
  158. }
  159.  
  160. .GridFooterText
  161. {
  162.   color: #000000;  
  163.   font-family: verdana;
  164.   font-size: 11px;
  165. }
  166.  
  167.  
  168.  
  169.  
  170.  
  171. .SortedDataCell
  172. {
  173.   background-color: #F5F5F5;
  174. }
  175.  
  176.  
  177. .Row td.LastDataCell
  178. {
  179.   background-color: #EFEFF4;
  180. }
  181.  
  182.  
  183. .GroupHeading
  184. {
  185.   color: #706F91;
  186.   background-color: #FFFFFF;
  187.   font-family: verdana;
  188.   font-weight: bold;
  189.   font-size: 11px;
  190.   border-bottom: 2px solid #A5A4BD;
  191.   padding-top: 10px;
  192.   padding-bottom: 3px;
  193. }
  194.  
  195. .GroupByCell
  196. {
  197.   cursor: pointer;
  198. }
  199.  
  200. .GroupByText
  201. {
  202.   color: #FFFFFF;
  203.   font-size: 11px;   
  204.   font-weight: bold;
  205.   padding-right: 5px;
  206. }
  207.  
  208.  
  209. .SliderPopup
  210. {
  211.   background-color: #FFF4D7;
  212.   border: 1px solid #4B4B6F;
  213.   border-top-color: #9495A2;
  214.   border-left-color: #9495A2;
  215.   font-size: 11px;
  216.   width: 150px;
  217.   height: 30px;
  218. }
  219.  
  220. .ScrollBar
  221. {
  222.   background-image: url(/images/scroller/scroller_bg.gif);
  223. }
  224.  
  225. .ScrollGrip
  226. {
  227.   background-image: url(/images/scroller/scroll_gripBg.gif);
  228. }
  229.  
  230. .ScrollPopup
  231. {
  232.   background-color: #FFFFFF;
  233.   border: 1px solid #666666;
  234.   border-right-width: 2px;
  235.   border-bottom-width: 2px;
  236.   height: 23px;
  237. }
  238.  
  239. .IndentCell
  240. {
  241.   BORDER-RIGHT: 0px;
  242.   BACKGROUND: #a9c7f4;
  243.   HEIGHT: 20px
  244. }
  245.  
  246. .EditDataCell
  247. {
  248.   padding: 0px!important;
  249.   font-size:8px;
  250.   background-color: #E2E2E2;
  251.   border-width:0px!important;
  252. }
  253.  
  254. .EditDataField
  255. {
  256.   padding: 0px;
  257.   padding-left: 1px;
  258.   font-family: verdana;
  259.   font-size: 10px;
  260.   height: 13px;
  261.   width: 98%!important;
  262. }

The Grid class:

 

Code Snippet
  1. Imports Microsoft.VisualBasic
  2.  
  3. Public Class ComponentArtGrid
  4.     Function setup(ByVal grid1 As ComponentArt.Web.UI.Grid) As ComponentArt.Web.UI.Grid
  5.         grid1.RunningMode = ComponentArt.Web.UI.GridRunningMode.Client
  6.         grid1.CssClass = "Grid"
  7.         grid1.ShowHeader = False
  8.         grid1.SearchTextCssClass = "GridHeaderText"
  9.         grid1.HeaderCssClass = "GridHeader"
  10.         grid1.ImagesBaseUrl = "~/images/"
  11.         grid1.TreeLineImagesFolderUrl = "~/images/lines/"
  12.         grid1.TreeLineImageWidth = "20"
  13.         grid1.TreeLineImageHeight = "19"
  14.         grid1.IndentCellWidth = "22"
  15.         grid1.LoadingPanelClientTemplateId = "LoadingFeedbackTemplate"
  16.  
  17.  
  18.         'paging
  19.         grid1.PagerTextCssClass = "GridFooterText"
  20.         grid1.FooterCssClass = "GridFooter2" 'this is for non-slider footers
  21.         grid1.PageSize = "15"
  22.         grid1.PagerStyle = ComponentArt.Web.UI.GridPagerStyle.Numbered 'or buttons or slider
  23.         grid1.PagerButtonWidth = "41"
  24.         grid1.PagerButtonHeight = "22"
  25.         grid1.SliderHeight = "20"
  26.         grid1.SliderWidth = "150"
  27.         grid1.SliderGripWidth = "9"
  28.         grid1.SliderPopupOffsetX = "20"
  29.         grid1.SliderPopupClientTemplateId = "SliderTemplate"
  30.         grid1.AllowMultipleSelect = False
  31.         'grid1.PagerImagesFolderUrl = "~/images/pager/"
  32.  
  33.         'grouping
  34.         'grid1.GroupingNotificationTextCssClass = "GridHeaderText"
  35.         grid1.GroupingNotificationText = "Drag a column to this area to group by it."
  36.         'grid1.GroupingPageSize = "5"
  37.         grid1.PreExpandOnGroup = "true"
  38.         grid1.GroupBySortAscendingImageUrl = "group_asc.gif"
  39.         grid1.GroupBySortDescendingImageUrl = "group_desc.gif"
  40.         grid1.GroupBySortImageWidth = "10"
  41.         grid1.GroupBySortImageHeight = "10"
  42.         grid1.GroupByCssClass = "GroupByCell"
  43.         grid1.GroupByTextCssClass = "GroupByText"
  44.         'grid1.LoadingPanelPosition = ComponentArt.Web.UI.GridRelativePosition.MiddleCenter
  45.  
  46.  
  47.         'grid level 1
  48.         With grid1.Levels(0)
  49.             .AllowGrouping = True 'false
  50.             .ShowTableHeading = False
  51.  
  52.             .ShowSelectorCells = True ' "false"
  53.             .RowCssClass = "Row"
  54.             .ColumnReorderIndicatorImageUrl = "reorder.gif"
  55.             .DataCellCssClass = "DataCell"
  56.             .HeadingCellCssClass = "HeadingCell"
  57.             .HeadingCellHoverCssClass = "HeadingCellHover"
  58.             .HeadingCellActiveCssClass = "HeadingCellActive"
  59.             .HeadingRowCssClass = "HeadingRow"
  60.             .HeadingTextCssClass = "HeadingCellText"
  61.             .SelectedRowCssClass = "SelectedRow"
  62.             .GroupHeadingCssClass = "GroupHeading"
  63.             .SortAscendingImageUrl = "asc.gif"
  64.             .SortDescendingImageUrl = "desc.gif"
  65.             .SortImageWidth = "10"
  66.             .SortImageHeight = "10"
  67.             .EditCellCssClass = "EditDataCell"
  68.             .EditFieldCssClass = "EditDataField"
  69.  
  70.  
  71.         End With
  72.         Return grid1
  73.     End Function
  74. End Class

The .aspx template:

Code Snippet
  1. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="EditLink.aspx.vb" Inherits="TEMPLATE_ComponentArt_Grid_EditLink" title="Untitled Page" %>
  2. <%@ Register Assembly="ComponentArt.Web.UI" Namespace="ComponentArt.Web.UI" TagPrefix="ComponentArt" %>
  3.  
  4. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  5.     <asp:Label ID="lblMessage" runat="server"></asp:Label><br />
  6.     
  7.                     <ComponentArt:Grid ID="Grid1"
  8.                         runat="server">
  9.                         <Levels>
  10.                             <ComponentArt:GridLevel
  11.                                 DataKeyField="intUserID" >
  12.                                 <Columns>
  13.                                     <ComponentArt:GridColumn DataCellServerTemplateId="LinkButtonTemplate" />
  14.                                     <ComponentArt:GridColumn DataField="intUserID" AllowGrouping="true" HeadingText="User ID" />
  15.                                     <ComponentArt:GridColumn DataField="vchrUserName" HeadingText="User Name" />
  16.                                 </Columns>
  17.                             </ComponentArt:GridLevel>
  18.                         </Levels>
  19.                         <ServerTemplates>
  20.                             <ComponentArt:GridServerTemplate Id="LinkButtonTemplate">
  21.                                 <template>
  22.                                     <asp:LinkButton ID="LinkButton1" Runat="server" text="GO" CommandName="Grid1_ItemCommand" CommandArgument='<%# Container.DataItem("intUserID") %>' />
  23.                                 </template>
  24.                             </ComponentArt:GridServerTemplate>
  25.                         </ServerTemplates>
  26.                     </ComponentArt:Grid>
  27.  
  28. </asp:Content>

 

The code behind:

 

Code Snippet
  1. Imports System.Data
  2.  
  3. Partial Class TEMPLATE_ComponentArt_Grid_EditLink
  4.     Inherits inheritedpage
  5.  
  6.  
  7.  
  8.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  9.  
  10.  
  11.         'set up the grid
  12.         Dim oGrid As New ComponentArtGrid
  13.         Me.Grid1 = oGrid.setup(Me.Grid1)
  14.         Grid1.Width = "300"
  15.  
  16.         bindgrid()
  17.     End Sub
  18.     Sub bindgrid()
  19.         Grid1.DataSource = dynData.SPs.FP_SOP10100_SEL_byID("", 0, AppUser.strLastDB).getTable
  20.  
  21.         Grid1.DataBind()
  22.  
  23.     End Sub
  24.  
  25.     Protected Sub Grid1_ItemCommand(ByVal sender As Object, ByVal e As ComponentArt.Web.UI.GridItemCommandEventArgs) Handles Grid1.ItemCommand
  26.         'there are three ways to get data from the grid:
  27.  
  28.         '1: in the Command Argument
  29.         Dim intUserID As Integer
  30.         Dim LinkButton1 As New LinkButton
  31.         'get a reference to the control
  32.         LinkButton1 = e.Control
  33.         'get the command argument
  34.         intUserID = LinkButton1.CommandArgument
  35.  
  36.         '2 from  a field in the grid
  37.         Dim strSopnumber As String
  38.         strSopnumber = e.Item("sopnumbe")
  39.  
  40.         '3 if the field is in a template, we have to search for it
  41.         Dim lblSoptype As Label
  42.         lblSoptype = CType(Me.Grid1.FindControl("lblSoptpe"), Label)
  43.         Dim intSoptype As Int16
  44.         intSoptype = lblSoptype.Text
  45.  
  46.  
  47.  
  48.     End Sub
  49. End Class

Tags:
Categories:
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us