473,397 Members | 2,099 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,397 software developers and data experts.

Null Exception - DataGridItem

Hi all,

The following code works fine.

If i remove the try statement, i recieve a generic is null exception when
trying to retrieve a datagrids data item.

With the try those exceptions are obviously caught, but it is clear the data
item is accessible otherwise as i am able to use its value.

I am just wondering (without the try statement) what the function could be
encountering to set of the null exception error.

Any thoughts?

Adam

Sub dgAnswerOptions_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

'determine if current item is not a header or footer
If(e.Item.ItemType <> ListItemType.Header Or e.Item.ItemType <>
ListItemType.Footer) Then

'add index to answer options
e.Item.Cells(0).Controls.Add(New
LiteralControl(e.Item.ItemIndex + 1 & "."))

'determin if logged in user belongs to the director or admin
groups
If(Security.IsDirector() Or Security.IsAdmin()) Then

Try

'determine if current option is a correct option
If(e.Item.DataItem.Item(2) = 1) Then //error occurs
here without try

'change cell formatting to reflect a correct
answer
e.Item.Cells(1).CssClass = "correct"
e.Item.Cells(1).Text = e.Item.Cells(1).Text & "
(Correct)"

End If

Catch

e.Item.Cells(1).Controls.Add(New LiteralControl("
Type: " & e.Item.ItemType))

End Try

End If

End If

End Sub
Nov 19 '05 #1
2 2365
The problem I think is that the data item may be null yet you are testing it
against nothing first

"Adam Knight" <ad**@pertrain.com.au> wrote in message
news:e4**************@tk2msftngp13.phx.gbl...
Hi all,

The following code works fine.

If i remove the try statement, i recieve a generic is null exception when
trying to retrieve a datagrids data item.

With the try those exceptions are obviously caught, but it is clear the
data item is accessible otherwise as i am able to use its value.

I am just wondering (without the try statement) what the function could be
encountering to set of the null exception error.

Any thoughts?

Adam

Sub dgAnswerOptions_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

'determine if current item is not a header or footer
If(e.Item.ItemType <> ListItemType.Header Or e.Item.ItemType <>
ListItemType.Footer) Then

'add index to answer options
e.Item.Cells(0).Controls.Add(New
LiteralControl(e.Item.ItemIndex + 1 & "."))

'determin if logged in user belongs to the director or admin
groups
If(Security.IsDirector() Or Security.IsAdmin()) Then

Try

'determine if current option is a correct option
If(e.Item.DataItem.Item(2) = 1) Then //error occurs
here without try

'change cell formatting to reflect a correct
answer
e.Item.Cells(1).CssClass = "correct"
e.Item.Cells(1).Text = e.Item.Cells(1).Text & "
(Correct)"

End If

Catch

e.Item.Cells(1).Controls.Add(New LiteralControl("
Type: " & e.Item.ItemType))

End Try

End If

End If

End Sub

Nov 19 '05 #2
You might try condition

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then

If(e.Item.ItemType <> ListItemType.Header Or e.Item.ItemType <>
ListItemType.Footer)
might catch some other items

HTH

Elton Wang

"Adam Knight" wrote:
Hi all,

The following code works fine.

If i remove the try statement, i recieve a generic is null exception when
trying to retrieve a datagrids data item.

With the try those exceptions are obviously caught, but it is clear the data
item is accessible otherwise as i am able to use its value.

I am just wondering (without the try statement) what the function could be
encountering to set of the null exception error.

Any thoughts?

Adam

Sub dgAnswerOptions_ItemDataBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

'determine if current item is not a header or footer
If(e.Item.ItemType <> ListItemType.Header Or e.Item.ItemType <>
ListItemType.Footer) Then

'add index to answer options
e.Item.Cells(0).Controls.Add(New
LiteralControl(e.Item.ItemIndex + 1 & "."))

'determin if logged in user belongs to the director or admin
groups
If(Security.IsDirector() Or Security.IsAdmin()) Then

Try

'determine if current option is a correct option
If(e.Item.DataItem.Item(2) = 1) Then //error occurs
here without try

'change cell formatting to reflect a correct
answer
e.Item.Cells(1).CssClass = "correct"
e.Item.Cells(1).Text = e.Item.Cells(1).Text & "
(Correct)"

End If

Catch

e.Item.Cells(1).Controls.Add(New LiteralControl("
Type: " & e.Item.ItemType))

End Try

End If

End If

End Sub

Nov 19 '05 #3

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

Similar topics

2
by: stanley j mroczek | last post by:
I read "Error Handling in SQL Server - a Background", http://www.algonet.se/~sommar/error-handling-I.html and "Implementing Error Handling with Stored Procedures",...
2
by: Chris Herring | last post by:
Hi there: Well, let me start off by saying that I am a Visual Studio drag and drop weenie, not a real programmer. So I tend to get confused when things do not look like the instructions said they...
0
by: Paul Perot | last post by:
Hi All: I am populating a Data Table with File/Folder information from my drive... I am then binding this data table to a DataGrid. Due to the size of the DataGrid data, I use the built in...
2
by: Richard Loupatty | last post by:
I put a datagrid in a panel with an overflow set on auto. I want to show just 5 items in the grid. My question is how to make sure that the selecteditem is always visible in the grid. Because...
5
by: I am Sam | last post by:
The codebehind is as follows: I have instenced the DataSet dsclub2a protected System.Data.DataSet dsclub2a; and I have instanced the DropdownList as follows: protected...
3
by: GD | last post by:
Got a simple ASPX page (.NET v1.1) with a DataGrid displaying a list of widgets. If the page has a QueryString called WidgetId specific, I need to automatically mark the specific DataGridItem as...
2
by: Mike Gaab | last post by:
VS 2005 What is the difference between the DataGridItem's ItemIndex and DataSetIndex? Aren't they the same thing? Here is what I found on msdn. ItemIndex Gets the index of the DataGridItem...
3
by: Steve Hershoff | last post by:
Hi everyone, I'm wondering if anyone has a suggestion on how to do this, or if it's even possible. In my datagrid's OnItemDataBound function I'd like to somehow "add" a child row beneath one...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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...
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,...

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.