473,406 Members | 2,619 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,406 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 6386

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.