Click here to Skip to main content
15,885,853 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It is master page code
XML
<asp:GridView ID="grdview" runat="server" CssClass="table table-bordered" AutoGenerateColumns="False" DataKeyNames="OwnId" OnRowEditing="grdview_RowEditing" OnPageIndexChanging="grdview_PageIndexChanging" OnRowCancelingEdit="grdview_RowCancelingEdit" OnRowUpdating="grdview_RowUpdating">

                                           </asp:GridView>


It is child page code
In child page give this error
"Object reference not set to an instance of an object."

public void Ownerbind()
{
GridView grdview = (GridView)Master.FindControl("grdview");
SqlConnection con = new SqlConnection(cn.ConnectionStrings);
String Bind = "SELECT [OwnId],[OwnerCode],[FirstName],[LastName],[MobileNo],[Email] FROM [WebCrm].[dbo].[tbl_Owner]";
con.Open();
adp = new SqlDataAdapter(Bind, con);
ds = new DataSet();
adp.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
grdview.DataSource = ds;
grdview.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
grdview.DataSource = ds;
grdview.DataBind();
int columncount = grdview.Rows[0].Cells.Count;
grdview.Rows[0].Cells.Clear();
grdview.Rows[0].Cells.Add(new TableCell());
grdview.Rows[0].Cells[0].ColumnSpan = columncount;
grdview.Rows[0].Cells[0].Text = "No Records Found";
}
}
Posted
Comments
DamithSL 22-Oct-15 1:18am    
in which line you get this error?
Radhika20 22-Oct-15 1:45am    
GridView grdview = (GridView)Master.FindControl("grdview");
In this line i get this error

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