I have gridview binded to a dumb business object. The business object had 30 fields & I only needed to display 8 in my gridview so the rest of fields of the business object were being wasted.
I was advised to design a DTO for this purpose. I have designed a DTO but it does not look any different than a dumb business object itself ?
Currently I have the DTO for the grid, its collection class List <DTO> and a DAL class. I am filling the DTO in DAL and returning it to presentation layer.
Is this the right way ? Do I have to make a base class for the DTO ?
My DTO atm looks like this
public class ftMasterSummaryDTO
{
private int ftId;
private DateTime entryDate=DateTime.MinValue;
private int ftYear;
private string ftCateg=string.Empty;
private string ftType=string.Empty;
public int FtId
{
get { return ftId; }
set { ftId = value; }
}
public DateTime EntryDate
{
get { return entryDate; }
set { entryDate = value; }
}
public int FtYear
{
get { return ftYear; }
set { ftYear = value; }
}
public string FtCateg
{
get { return ftCateg; }
set { ftCateg = value; }
}
public string FtType
{
get { return ftCateg; }
set { ftCateg = value; }
}
}
Use
ObjectDataSourceto bind the GridView to your custom-business-objects. Create a DTOManager class that shall return the IList for your DTOs. Then in the design-mode of the GridView you can remove the coloumns you do not wish to display.Your DTOManager class may look like this.