绑定网格到接口类型转换类在创建模板字段时获取类属性 [英] bind grid to interface-type cast class get class properties when creating template fields

查看:48
本文介绍了绑定网格到接口类型转换类在创建模板字段时获取类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个类作为类

具有8个属性或列的服务在gridview中显示 - 所有标签

具有5个属性或列的员工显示 - 一列有复选框

产品有7个属性或列显示 - 一列有单选按钮



需要在网页中显示网格。每个类别的一个网页

而不是创建3个网格 - 显示它们(我现在正在做的)。我想在usercontrol中创建一个网格。在运行时,基于类别绑定到类,创建模板字段并绑定它。我该怎么做?



现在 -

我有3个类继承自界面



在usercontrol中 - 我有一个属性列表< interface> listIGS。根据类别,我想输入这个listIGS到类,创建模板字段并添加到网格和显示。



我该怎么做? - 示例代码。卡在我遍历列表的行中,并获取属性名称以创建模板字段。请帮助!!



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())//如何//通过接口的属性将类接口强制转换为类并迭代

//创建模板?

$

}

TableGridView.DataSource = listIGS.ToArray();

TableGridView.DataBind();





}

}

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();


}
}

推荐答案

这篇关于绑定网格到接口类型转换类在创建模板字段时获取类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆