Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have 3 categories as classes
Service with 8 properties or columns to show in gridview -all label
Employee with 5 properties or columns to show-one column has check box
Product with 7 properties or columns to show-one column has radio button

Need to display in grid in webpages. one web page for each category
Instead of creating 3 grids -to show them(which I am doing right now). I would like to create a single grid in usercontrol. At runtime bind to classes based on category, create template fields and bind it. How do I do it?

Right now -
I have 3 classes inherit from a interface

In the usercontrol-I have a property list<interface>listIGS. Based on the category, I want to type cast this listIGS to the class, create the templatefields and add to grid and display.

How do I do it? --sample code. stuck in the line where I iterate through the list and get the properties name to create the template field. Please help!!

public static List<igridclassinterfacecs> listIGS;
public string Category = "Service";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Category == "Service")
{
MeetingServices ms = new MeetingServices();
listIGS = ms.getList();
}
foreach (var prop in listIGS[0].GetType().GetProperties())//how to I //typecast the interface to class and iterate
//through the properties of interface and create the templates?
{
}
TableGridView.DataSource = listIGS.ToArray();
TableGridView.DataBind();


}
}
Posted
Updated 25-Apr-14 0:27am
v3

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