Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I created a user control contain aspxgridview and page contain this user control and button when i click on the button in the page i pass values to methods in my user control
this code in the page pass values to method in user control

C#
protected void ASPxButton1_Click(object sender, EventArgs e)
        {
            DisplayAttachmentControl d = new DisplayAttachmentControl();
            d.DisplayData(5, null);
        }


this is the method in my user control

C#
public void DisplayData(int? documentId, int? ticketId)
        {
            Attachments attachment = new Attachments();
            dt = attachment.GetAttachmentByDocumentIDorTicketID(documentId, null);
 
            ASPxGridView1.DataSource = dt;
            ASPxGridView1.DataBind();
        }


the problem is when i pass datatable to aspxgridview1 this error appear

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

1 solution

Start by looking at your GetAttachmentByDocumentIDorTicketID method: I'm just guessing that it doesn't find any matching values and as a result it doesn't return a DataTable.

Use the debugger, and check what it returns - if it's null, then you need to step into your method and work out why.
We can;t do that for you - we don't have any access to your code or data, and can;t run you application!
 
Share this answer
 
Comments
tranesyasd 31-Aug-15 5:09am    
the datatable return value the problem is when i use the grid in the method it be null i donot know why?
OriginalGriff 31-Aug-15 5:27am    
We can't tell you what to do - you need to look yourself (we can't access your HDD!)
So which value is null, and which line it the error reported on.
Use the debugger, and tell us.
tranesyasd 31-Aug-15 5:10am    
i tried to use my grid using findcontrol method the same error appear
tranesyasd 31-Aug-15 5:33am    
when i used debugger every thing ok and dt returned rows
when i reach the line
ASPxGridView1.DataSource = dt;
the ASPxGridView1 is null
i think its null because i access it from another page
OriginalGriff 31-Aug-15 5:58am    
You can't access a GridView on a different page!

What are you trying to do, exactly?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900