新建一个类 并继承ITemplate
[c#]
public class DataGridTemplate : ITemplate {
// put your code here...
}
然后重写InstantiateIn方法。在此方法内可以按照常规方式动态创建控件,比如CheckBox
[c#]
CheckBox chk = new CheckBox();
container.Controls.Add(chk);//container是InstantiateIn方法的参数,你将一个类继承ITemplate接口后,按TAB键将会自动生成接口成员代码。
//看一下自动生成的public void InstantiateIn(Control container)就明白了最后在你需要动态创建TemplateColumn的地方,写:
TemplateColumn tc1 = new TemplateColumn(); // 创建一个模板列(来自系统)
tc1.ItemTemplate = new DataGridTemplate("categoryname"); // DataGridTemplate 是你刚才创建继承ITemplate接口的类
[c#]
public class DataGridTemplate : ITemplate {
// put your code here...
}
然后重写InstantiateIn方法。在此方法内可以按照常规方式动态创建控件,比如CheckBox
[c#]
CheckBox chk = new CheckBox();
container.Controls.Add(chk);//container是InstantiateIn方法的参数,你将一个类继承ITemplate接口后,按TAB键将会自动生成接口成员代码。
//看一下自动生成的public void InstantiateIn(Control container)就明白了最后在你需要动态创建TemplateColumn的地方,写:
TemplateColumn tc1 = new TemplateColumn(); // 创建一个模板列(来自系统)
tc1.ItemTemplate = new DataGridTemplate("categoryname"); // DataGridTemplate 是你刚才创建继承ITemplate接口的类
解决方案 »
- 一个sql复合主键的更新问题,哪位大哥顺路来解答一下,谢谢
- 从oracle中查出数据绑定到GridView
- 验证码的问题
- window.print(),如何隐藏或去掉打印后显示的网址
- 使用AspNetPager7.01的问题
- Repeater问题
- 如何给TextBox的值赋一个超连结,如<a Target='_self' href='frmDHubDetail.aspx?pType=InFactory'><font color='blue'>This is a test</f
- Ajax:返回状态值为Not Found,我的url检查几次都没有问题
- 【用Winsock发送数据包后,如何判断接收端是否收到包?】
- 传递参数在MS提供的数据访问块里面怎么用呢?是不是和带参数的存储过程的访问形式是一样的呢?
- 急:一个很菜的问题
- 身份验证问题??
tc1.ItemTemplate = new DataGridTemplate("categoryname"); // 这里的"categoryname"是你自己所写构造函数,根据实际需要自己来写