I have an array of business objects. Each of these objects has four properties: id name description icon I am trying to bind this array of objects to a datagrid and am getting a blank page. Here is the code in the class behind:
public class family : System.Web.UI.Page
{
DataGrid dg;
private void Page_Load(object sender, System.EventArgs e)
{
ReportFamily rf = new ReportFamily();
ReportFamilyInfo[] rfi = rf.GetAllReportFamilies();
dg = new DataGrid();
dg.DataSource = rfi;
dg.DataBind();
}
...
}
Here is the code in the aspx:
I apologize fo rthe elementary
question but this is the first time i've tried binding to anything other than a dataset. If you could provide specific code it would be much appreciated Thanks
but if i return an arraylist i will lose my typed array. I know i could create a datatable, loop over my typed array and build a datarow for each entry, then bind the datagrid to that datatable, but it seems to me I shouldnt have to this. My array is typed,
all entries will have the same props, why cant it go through?
Help! I'm obviously missing something simple but I've wasted a couple hours on this now and it's driving me crazy! Here is my code behind, family.aspx.cs:
public class family : System.Web.UI.Page
{
DataGrid dg = new DataGrid();
private void Page_Load(object sender, System.EventArgs e)
{
ReportFamily rf = new ReportFamily();
ReportFamilyInfo[] rfi = rf.GetAllReportFamilies();
DataTable dt = new DataTable();
DataColumn idColumn = new DataColumn();
idColumn.DataType = System.Type.GetType("System.Int32");
idColumn.ColumnName = "id";
dt.Columns.Add(idColumn);
DataColumn nameColumn = new DataColumn();
nameColumn.DataType = System.Type.GetType("System.String");
nameColumn.ColumnName = "Name";
dt.Columns.Add(nameColumn);
DataColumn descColumn = new DataColumn();
descColumn.DataType = System.Type.GetType("System.String");
descColumn.ColumnName = "Description";
dt.Columns.Add(descColumn);
DataColumn iconColumn = new DataColumn();
iconColumn.DataType = System.Type.GetType("System.String");
iconColumn.ColumnName = "Icon";
dt.Columns.Add(iconColumn);
DataRow dr;
foreach (ReportFamilyInfo myRfi in rfi)
{
dr = dt.NewRow();
dr["id"] = myRfi.Id;
dr["Name"] = myRfi.Name;
dr["Description"] = myRfi.Description;
dr["Icon"] = myRfi.Icon;
dt.Rows.Add(dr);
}
dg.DataSource = dt.DefaultView;
dg.DataBind();
}
....
it is my understanding that public BusinessObject[] getAllBusinessObjects {} is better than public ArrayList getAllBusinessObjects() in the business logic layer of an ntier architecture
cwr
Member
130 Points
26 Posts
Binding to an array of Business Objects
Sep 23, 2003 03:00 PM|LINK
public class family : System.Web.UI.Page { DataGrid dg; private void Page_Load(object sender, System.EventArgs e) { ReportFamily rf = new ReportFamily(); ReportFamilyInfo[] rfi = rf.GetAllReportFamilies(); dg = new DataGrid(); dg.DataSource = rfi; dg.DataBind(); } ... }Here is the code in the aspx:
I apologize fo rthe elementary question but this is the first time i've tried binding to anything other than a dataset. If you could provide specific code it would be much appreciated Thanksswall
Member
140 Points
28 Posts
Re: Binding to an array of Business Objects
Sep 23, 2003 03:05 PM|LINK
cwr
Member
130 Points
26 Posts
Re: Binding to an array of Business Objects
Sep 23, 2003 03:35 PM|LINK
cwr
Member
130 Points
26 Posts
Re: Binding to an array of Business Objects
Sep 23, 2003 06:23 PM|LINK
public class family : System.Web.UI.Page { DataGrid dg = new DataGrid(); private void Page_Load(object sender, System.EventArgs e) { ReportFamily rf = new ReportFamily(); ReportFamilyInfo[] rfi = rf.GetAllReportFamilies(); DataTable dt = new DataTable(); DataColumn idColumn = new DataColumn(); idColumn.DataType = System.Type.GetType("System.Int32"); idColumn.ColumnName = "id"; dt.Columns.Add(idColumn); DataColumn nameColumn = new DataColumn(); nameColumn.DataType = System.Type.GetType("System.String"); nameColumn.ColumnName = "Name"; dt.Columns.Add(nameColumn); DataColumn descColumn = new DataColumn(); descColumn.DataType = System.Type.GetType("System.String"); descColumn.ColumnName = "Description"; dt.Columns.Add(descColumn); DataColumn iconColumn = new DataColumn(); iconColumn.DataType = System.Type.GetType("System.String"); iconColumn.ColumnName = "Icon"; dt.Columns.Add(iconColumn); DataRow dr; foreach (ReportFamilyInfo myRfi in rfi) { dr = dt.NewRow(); dr["id"] = myRfi.Id; dr["Name"] = myRfi.Name; dr["Description"] = myRfi.Description; dr["Icon"] = myRfi.Icon; dt.Rows.Add(dr); } dg.DataSource = dt.DefaultView; dg.DataBind(); } ....and here is my .asxpx - family.aspx For the life of me I can't figure out where I'm going wrong!swall
Member
140 Points
28 Posts
Re: Binding to an array of Business Objects
Sep 23, 2003 08:41 PM|LINK
cwr
Member
130 Points
26 Posts
Re: Binding to an array of Business Objects
Sep 24, 2003 01:09 AM|LINK
swall
Member
140 Points
28 Posts
Re: Binding to an array of Business Objects
Sep 24, 2003 03:33 PM|LINK
cwr
Member
130 Points
26 Posts
Re: Binding to an array of Business Objects
Sep 24, 2003 04:17 PM|LINK
swall
Member
140 Points
28 Posts
Re: Binding to an array of Business Objects
Sep 24, 2003 06:56 PM|LINK
cwr
Member
130 Points
26 Posts
Re: Binding to an array of Business Objects
Sep 24, 2003 09:16 PM|LINK