473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

GridView

Hello,

I am trying to create a ItemTemplate at runtime for a ComponentArt
Grid.

This GridView works in a very similar way to the Asp.Net 2.0 GridView
so the implementation method should be the same.

When I don't use the ItemTemplate everything works fine.

However, when I use the ItemTemplate I get the following error:

"Exception Details: System.NullReferenceException: Object reference
not set to an instance of an object."

On the code line

lCollaborator.Text = tcCollaborator.DataItem("Name").ToString &
tcCollaborator.DataItem("City").ToString

I think my problem is really the binding method.

Could someone please tell me what might be wrong? I also tried using
the Asp.Net 2.0 GridView and I am getting the same problems.

I post my VB.NET code. Please, fell free to answer in VB.NET or C#.

GRID.aspx.vb

1 Partial Class Grid
2 Inherits System.Web.UI.Page
3
4 ' -- [Controls] -------------------------------------------
5
6 Protected WithEvents cagCollaborators As New
ComponentArt.Web.UI.Grid
7
8
9 ' -- [Events and Methods]
-------------------------------------------
10
11 ' Page_Init
12 Protected Sub Page_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Init
13
14 phGrid.Controls.Add(cagCollaborators)
15
16 End Sub ' Page_Init
17
18 ' Page_Load
19 Protected Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
20
21 ' Create grid server template
22 Dim cagstCollaborators As ComponentArt.Web.UI.GridServerTemplate
= New ComponentArt.Web.UI.GridServerTemplate()
23
24 ' Create grid template
25 Dim gitCollaborators As GridITemplate = New GridITemplate
26 cagstCollaborators.Template = gitCollaborators
27 cagstCollaborators.ID = "cagstCollaborators"
28
29 ' Add grid server template to grid
30 cagCollaborators.ServerTemplates.Add(cagstCollabor ators)
31
32 ' Create grid column
33 Dim gcCollaborators As ComponentArt.Web.UI.GridColumn = New
ComponentArt.Web.UI.GridColumn
34 gcCollaborators.DataCellServerTemplateId = "cagstCollaborators"
35
36 ' Create grid level
37 Dim glCollaborators As New ComponentArt.Web.UI.GridLevel
38 glCollaborators.Columns.Add(gcCollaborators)
39
40 ' Add grid level to grid
41 cagCollaborators.Levels.Add(glCollaborators)
42
43 ' Bind grid
44 cagCollaborators.DataBind()
45
46 End Sub ' Page_Load
47
48 ' {Grid} ...
49
50 ' cagCollaborators_Init
51 Private Sub cagCollaborators_Init(ByVal sender As Object, ByVal e
As EventArgs) Handles cagCollaborators.Init
52
53 ' Define cagCollaborators properties
54 With cagCollaborators
55 .ApplyStyleSheetSkin(Me.Page)
56 .AllowEditing = False
57 .ID = "cagCollaborators"
58 .RunningMode = GridRunningMode.Client
59 .ShowHeader = False
60 .Width = Unit.Percentage(100)
61 End With
62
63 End Sub ' cagCollaborators_Init
64
65 ' cagCollaborators_NeedRebind
66 Public Sub cagCollaborators_NeedRebind(ByVal sender As Object,
ByVal oArgs As System.EventArgs) Handles cagCollaborators.NeedRebind
67
68 ' Bind grid
69 cagCollaborators.DataBind()
70
71 End Sub ' cagCollaborators_NeedRebind
72
73 ' cagCollaborators_NeedDataSource
74 Public Sub cagCollaborators_NeedDataSource(ByVal sender As
Object, ByVal oArgs As System.EventArgs) Handles
cagCollaborators.NeedDataSource
75
76 ' Define collaborators grid datasource
77 cagCollaborators.DataSource = Collaborators()
78
79 ' Bind collaborators grid
80 cagCollaborators.DataBind()
81
82 End Sub ' cagCollaborators_NeedDataSource
83
84 ' cagCollaborators_PageIndexChanged
85 Public Sub cagCollaborators_PageIndexChanged(ByVal sender As
Object, ByVal oArgs As
ComponentArt.Web.UI.GridPageIndexChangedEventArgs) Handles
cagCollaborators.PageIndexChanged
86
87 ' Define current page index
88 cagCollaborators.CurrentPageIndex = oArgs.NewIndex
89
90 End Sub ' cagCollaborators_PageIndexChanged
91
92 ' Collaborators
93 Public Shared Function Collaborators() As DataTable
94
95 ' Create collaborators data table
96 Dim dtCollaborators As New DataTable
97
98 ' Add columns to collaborators data table
99 With dtCollaborators.Columns
100 .Add(New DataColumn("Name", GetType(String)))
101 .Add(New DataColumn("Mobile", GetType(String)))
102 .Add(New DataColumn("Email", GetType(String)))
103 .Add(New DataColumn("City", GetType(String)))
104 End With
105
106 ' Create and add a new collaborator row
107 Dim drRow01 As DataRow
108 drRow01 = dtCollaborators.NewRow
109
110 ' Define collaborator row values
111 drRow01("Name") = "John"
112 drRow01("Mobile") = "983498223"
113 drRow01("Email") = "jo**@mydomain.com"
114 drRow01("City") = "New York"
115
116 ' Add row to collaborators data table
117 dtCollaborators.Rows.Add(drRow01)
118
119 ' Create and add a new collaborator row
120 Dim drRow02 As DataRow
121 drRow02 = dtCollaborators.NewRow
122
123 ' Define collaborator row values
124 drRow02("Name") = "Andrew"
125 drRow02("Mobile") = "983498223"
126 drRow02("Email") = "an****@mydomain.com"
127 drRow02("City") = "Paris"
128
129 ' Add row to collaborators data table
130 dtCollaborators.Rows.Add(drRow02)
131
132 ' Return collaborators data table
133 Return dtCollaborators
134
135 End Function ' Collaborators
136
137
138 ' -- [Sub Classes] -------------------------------------------
139
140 Public Class GridITemplate
141 Implements System.Web.UI.ITemplate
142
143
144 ' -- [Controls] -------------------------------------------
145
146 ' ---- {ASP.NET} ----
147
148 ' {Label} ...
149 Protected WithEvents lCollaborator As New Label
150
151 ' -- [Events and Methods]
-------------------------------------------
152
153 ' {Label} ...
154
155 ' lCollaborator_Init
156 Private Sub lCollaborator_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lCollaborator.Init
157
158 ' Define lCollaborator properties
159 With lCollaborator
160 .CssClass = Me.CssClass
161 .ID = "lCollaborator"
162 End With
163
164 End Sub ' lCollaborator_Init
165
166
167 ' ---- {ASP.NET Item Template} ----
168
169 ' InstantiateIn
170 Public Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn
171
172 ' Define template container
173 Dim tcCollaborator As
ComponentArt.Web.UI.GridServerTemplateContainer
174 tcCollaborator = CType(container,
ComponentArt.Web.UI.GridServerTemplateContainer)
175
176 ' Define lCollaborator text
177 lCollaborator.Text = tcCollaborator.DataItem("Name").ToString &
tcCollaborator.DataItem("City").ToString
178
179 ' Add item template child controls
180 container.Controls.Add(lCollaborator)
181
182 End Sub ' InstantiateIn
183
184 End Class ' GridITemplate
185
186 End Class
187
188
189

Thank You Very Much,

Miguel

Jan 31 '07 #1
0 6360

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
1
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
6
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.