Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,


I have a page P1.aspx and a user control UC1 inside it having bindgrid(int id) funtion as below.

C#
public void bindgrid(int id)
       {

           DataSet ds = XYZLogic.GetFiles(id,1);
           if (ds.Tables[0].Rows.Count > 0)
           {
               grdRegulationFile.DataSource = ds.Tables[0];
               grdRegulationFile.DataBind();
           }
           else
           {
               grdRegulationFile.DataSource = null;
               grdRegulationFile.DataBind();
           }
       }


Now I have another user control UC2 that is called in UC1. In UC2 I have a button and on click of that I want to bindgrid() of UC1.


I have done something like below.
C#
protected void btnSubmit_ServerClick(object sender, EventArgs e)
       {
           UC2 ad = new UC2();
           ad.bindgrid(1);
       }



but i am getting null value reference.
Please help me.
Posted
Updated 29-Nov-15 23:05pm
v2
Comments
F-ES Sitecore 30-Nov-15 5:24am    
What line gives the null reference?
Mohd Wasif 30-Nov-15 5:36am    
These below lines are giving errors.
grdRegulationFile.DataSource = ds.Tables[0];
F-ES Sitecore 30-Nov-15 5:56am    
Either grdRegulationFile is null or ds is null. We can't run your code, you're just going to have to learn how to debug. It's more likely that grdRegulationFile is null because you can't create instances of controls the way you are, you can't just create a new instance of the class. Google for examples of how you create user controls

https://msdn.microsoft.com/en-us/library/c0az2h86.aspx
Anil Sharma1983 30-Nov-15 7:22am    
i think grdRegulationFile is null.Please check
Richard Deeming 30-Nov-15 7:43am    
If you're trying to call a method in an existing instance of UC1, you can't just create a new instance of the class and call the method on that instance. You need a way to call the method on the existing instance.

The best option is probably to raise an event from UC2, and handle it in UC1.

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