473,473 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

grid view error

7 New Member
Expand|Select|Wrap|Line Numbers
  1. void GridView1_DataBound(object sender, EventArgs e)
  2.     {
  3.              DropDownList ddl = (DropDownList)GridView1.FindControl("drpmarks");
  4.              DataTable dt=  ClassLibrary1.Class1.FetchMarks( 21);
  5.       ddl.DataSource = dt;
  6.         ddl.DataTextField = "Marks";
  7.         ddl.DataValueField = "employeeid";
  8.         ddl.DataBind();
  9.  
  10.     }
  11.  
when i run iam getting error as null reference . can any body tell what is the problem
Nov 16 '07 #1
8 952
kenobewan
4,871 Recognized Expert Specialist
Your data table is prob empty, which line is the error?
Nov 16 '07 #2
mzmishra
390 Recognized Expert Contributor
Does this line returns a DataTable
ClassLibrary1.Class1.FetchMarks( 21)
Nov 16 '07 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1. void GridView1_DataBound(object sender, EventArgs e)
  2.     {
  3.              DropDownList ddl = (DropDownList)GridView1.FindControl("drpmarks");
  4.              DataTable dt=  ClassLibrary1.Class1.FetchMarks( 21);
  5.       ddl.DataSource = dt;
  6.         ddl.DataTextField = "Marks";
  7.         ddl.DataValueField = "employeeid";
  8.         ddl.DataBind();
  9.  
  10.     }
  11.  
when i run iam getting error as null reference . can any body tell what is the problem
Make sure that your GridView has the dropDownList "drpmarks" and also that your ClassLibrary1.Class1.FetchMarks returns an object to you that exists (is not null).

I also suggest changing your code to use a Try/Catch block so that you can set the NULL object to a reference of something when this occurs.

-Frinny
Nov 16 '07 #4
nehaneha
7 New Member
Your data table is prob empty, which line is the error?

no my datatable is not empty in dt iam getting 5 records but still iam getting an error . can't we bind directly datatable like that
Nov 19 '07 #5
nehaneha
7 New Member
Does this line returns a DataTable
ClassLibrary1.Class1.FetchMarks( 21)

yes it is returning 5 records . can't we bind datatable directly
Nov 19 '07 #6
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Could you please mention which line is the error being reported?
Nov 19 '07 #7
nehaneha
7 New Member
Could you please mention which line is the error being reported?

ddl.DataSource = mytable;

in this line iam getting an error

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:


Line 87: }
Line 88:
Line 89: ddl.DataSource = mytable;
Line 90: ddl.DataTextField = "Rank";
Line 91: ddl.DataValueField = "ProposalID";
Nov 19 '07 #8
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Hi nehaneha
This only means that
Expand|Select|Wrap|Line Numbers
  1. DataTable dt=  ClassLibrary1.Class1.FetchMarks( 21);
is returning null.
So maybe its time to revisit that code.
I am unaware of what object type ClassLibrary1.Class1 is
If it is fetching values from a database, you should check the SQL statement being genereated and the actual result of it.

cheers
Nov 19 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
2
by: Jan Mueller | last post by:
Hi all, I don't know whether this is the right group, let me know :-). I tried to open this XML file (with internal DTD) with XMLSpy 2005. I guess some of you also use this tool. ...
4
by: Filippo Pandiani | last post by:
I have a grid that shows the file list from a folder. On the postback, how do I get a Dataset from this grid? Thanks, Filippo.
5
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes,...
0
by: ¿ Mahesh Kumar | last post by:
I have created a XML file as datasource which i 'm binding to a grid view control. During runtime I'm capturing items in XML file and displaying in a GRID VIEW control. but i want to remove or...
10
by: John Wilson | last post by:
My app produces some long datatables to display in a grid. So I put them in a div so users can scroll. But the grid headers scroll out of view. I would like to stop them doing this. Can I fix them...
2
by: Umeshnath | last post by:
Hi, I have placed a grid view inside Atlas panel. On click of a button event, data is populated in the grid view, I want to add scroll bar instead of increasing the size of grid view. I have...
0
by: zafar | last post by:
I don't know what property should be used for hiding colums in Data Grid, whereas in Data Grid View we have DataGridView1.Colums(index).Visible = False , But how can I hide Colums in Data Grid.....
1
by: =?Utf-8?B?TG95b2xhIHN0YWxpbg==?= | last post by:
Hi, I am using ASP.Net 2.0 version and Windows'XP OS. I am useing the Grid view control to display the user details along with the paging concept provided by the grid view control. When i...
2
by: rameshgohil | last post by:
I am using grid view and a button column in it using <itemTemplate> but I am not able to rerive cell value of a selected row from grid view. I have tried the following to methods in Row_command...
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
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
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,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
1
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...
0
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.