473,796 Members | 2,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.NullRefe renceException: Object reference
not set to an instance of an object."

On the code line

lCollaborator.T ext = 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.P age
3
4 ' -- [Controls] -------------------------------------------
5
6 Protected WithEvents cagCollaborator s As New
ComponentArt.We b.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(cagCollabo rators)
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 cagstCollaborat ors As ComponentArt.We b.UI.GridServer Template
= New ComponentArt.We b.UI.GridServer Template()
23
24 ' Create grid template
25 Dim gitCollaborator s As GridITemplate = New GridITemplate
26 cagstCollaborat ors.Template = gitCollaborator s
27 cagstCollaborat ors.ID = "cagstCollabora tors"
28
29 ' Add grid server template to grid
30 cagCollaborator s.ServerTemplat es.Add(cagstCol laborators)
31
32 ' Create grid column
33 Dim gcCollaborators As ComponentArt.We b.UI.GridColumn = New
ComponentArt.We b.UI.GridColumn
34 gcCollaborators .DataCellServer TemplateId = "cagstCollabora tors"
35
36 ' Create grid level
37 Dim glCollaborators As New ComponentArt.We b.UI.GridLevel
38 glCollaborators .Columns.Add(gc Collaborators)
39
40 ' Add grid level to grid
41 cagCollaborator s.Levels.Add(gl Collaborators)
42
43 ' Bind grid
44 cagCollaborator s.DataBind()
45
46 End Sub ' Page_Load
47
48 ' {Grid} ...
49
50 ' cagCollaborator s_Init
51 Private Sub cagCollaborator s_Init(ByVal sender As Object, ByVal e
As EventArgs) Handles cagCollaborator s.Init
52
53 ' Define cagCollaborator s properties
54 With cagCollaborator s
55 .ApplyStyleShee tSkin(Me.Page)
56 .AllowEditing = False
57 .ID = "cagCollaborato rs"
58 .RunningMode = GridRunningMode .Client
59 .ShowHeader = False
60 .Width = Unit.Percentage (100)
61 End With
62
63 End Sub ' cagCollaborator s_Init
64
65 ' cagCollaborator s_NeedRebind
66 Public Sub cagCollaborator s_NeedRebind(By Val sender As Object,
ByVal oArgs As System.EventArg s) Handles cagCollaborator s.NeedRebind
67
68 ' Bind grid
69 cagCollaborator s.DataBind()
70
71 End Sub ' cagCollaborator s_NeedRebind
72
73 ' cagCollaborator s_NeedDataSourc e
74 Public Sub cagCollaborator s_NeedDataSourc e(ByVal sender As
Object, ByVal oArgs As System.EventArg s) Handles
cagCollaborator s.NeedDataSourc e
75
76 ' Define collaborators grid datasource
77 cagCollaborator s.DataSource = Collaborators()
78
79 ' Bind collaborators grid
80 cagCollaborator s.DataBind()
81
82 End Sub ' cagCollaborator s_NeedDataSourc e
83
84 ' cagCollaborator s_PageIndexChan ged
85 Public Sub cagCollaborator s_PageIndexChan ged(ByVal sender As
Object, ByVal oArgs As
ComponentArt.We b.UI.GridPageIn dexChangedEvent Args) Handles
cagCollaborator s.PageIndexChan ged
86
87 ' Define current page index
88 cagCollaborator s.CurrentPageIn dex = oArgs.NewIndex
89
90 End Sub ' cagCollaborator s_PageIndexChan ged
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("Nam e", GetType(String) ))
101 .Add(New DataColumn("Mob ile", GetType(String) ))
102 .Add(New DataColumn("Ema il", GetType(String) ))
103 .Add(New DataColumn("Cit y", 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(drRow 01)
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****@mydomai n.com"
127 drRow02("City") = "Paris"
128
129 ' Add row to collaborators data table
130 dtCollaborators .Rows.Add(drRow 02)
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.I Template
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_I nit
156 Private Sub lCollaborator_I nit(ByVal sender As Object, ByVal e As
System.EventArg s) Handles lCollaborator.I nit
157
158 ' Define lCollaborator properties
159 With lCollaborator
160 .CssClass = Me.CssClass
161 .ID = "lCollabora tor"
162 End With
163
164 End Sub ' lCollaborator_I nit
165
166
167 ' ---- {ASP.NET Item Template} ----
168
169 ' InstantiateIn
170 Public Sub InstantiateIn(B yVal container As Control) Implements
ITemplate.Insta ntiateIn
171
172 ' Define template container
173 Dim tcCollaborator As
ComponentArt.We b.UI.GridServer TemplateContain er
174 tcCollaborator = CType(container ,
ComponentArt.We b.UI.GridServer TemplateContain er)
175
176 ' Define lCollaborator text
177 lCollaborator.T ext = tcCollaborator. DataItem("Name" ).ToString &
tcCollaborator. DataItem("City" ).ToString
178
179 ' Add item template child controls
180 container.Contr ols.Add(lCollab orator)
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 6505

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

Similar topics

3
5677
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 GridView to allow entry of quantity and Y/N switch for
6
3041
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 current_row_key of Grid1... to the objectDataSource2 parameter? (so that the second grid, gets only the information to do with current row of grid1)
7
14821
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 want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
5
4841
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 automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
1
5216
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 the GridView does not display. I've debugged the DataTable and even when it has data and is bound to the GridView, when the page loads the GridView is not displayed. I set the datasource and then bind the GridView. I've tried disabling the...
3
4608
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 datasource to this GridView in runtime. But I cannot
2
13202
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 fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
5
3008
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 list that corresponds with the number of pages, but I am unable to wire up the Selected Index Changed event. Auto PostBack is set to true and the page is posting back when the DDL is selected / chaged, but the event is never being called. Any...
6
5762
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 OnSelectedIndexChanged event set on it. This triggers just fine, but within the codebehind of the OnSelectedIndexChanged event, I need to scan through all the entries in the nested GridView (to see if the user changed a value to an already existing value in the...
3
5247
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 DataTable, I am using List of Objects. Here's one example: http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10465
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.