K
kalaivanan
hi,
i am trying to add a datagrid control to a web page dynamically.
i am able to do it while i used the following code in the page load
event of the form in which i am going to add the control.
DataGrid dG = new DataGrid();
Control frm = FindControl("frmSnAInformation");
frm.Controls.Add(dG);
DataSet ds = nam_Db.dbFunctions.funFetchDataSet("fetchSuInfo_all");
dG.DataSource = ds.Tables[0];
dG.DataBind();
since i need to do the same process for many forms i have written the
code in a class file and call the function when needed. also i am
passing the form name as parameter. the class file function is as
follows:
public void funGrid(string frmNam)
{
DataGrid dG = new DataGrid();
Control frm = FindControl(frmANam);
frm.Controls.Add(dG);
DataSet ds = nam_Db.dbFunctions.funFetchDataSet("fetchSuInfo_all");
dG.DataSource = ds.Tables[0];
dG.DataBind();
}
but when i try to add control i am getting the following error:
System.NullReferenceException: Object reference not set to an instance
of an object.
at the line: frm.Controls.Add(dG);
what could be the reason and the work around for this problem.
regards,
kalaivanan
i am trying to add a datagrid control to a web page dynamically.
i am able to do it while i used the following code in the page load
event of the form in which i am going to add the control.
DataGrid dG = new DataGrid();
Control frm = FindControl("frmSnAInformation");
frm.Controls.Add(dG);
DataSet ds = nam_Db.dbFunctions.funFetchDataSet("fetchSuInfo_all");
dG.DataSource = ds.Tables[0];
dG.DataBind();
since i need to do the same process for many forms i have written the
code in a class file and call the function when needed. also i am
passing the form name as parameter. the class file function is as
follows:
public void funGrid(string frmNam)
{
DataGrid dG = new DataGrid();
Control frm = FindControl(frmANam);
frm.Controls.Add(dG);
DataSet ds = nam_Db.dbFunctions.funFetchDataSet("fetchSuInfo_all");
dG.DataSource = ds.Tables[0];
dG.DataBind();
}
but when i try to add control i am getting the following error:
System.NullReferenceException: Object reference not set to an instance
of an object.
at the line: frm.Controls.Add(dG);
what could be the reason and the work around for this problem.
regards,
kalaivanan