473,668 Members | 2,392 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 6480

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

Similar topics

3
5673
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
3032
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
14802
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
4831
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
5211
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
4599
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
13179
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
2992
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
5749
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
5233
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
8459
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
8378
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
8890
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
8791
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...
1
6206
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4202
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2786
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
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1783
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.