以编程方式将模板列添加到gridview [英] Programmatically add template columns to gridview

查看:148
本文介绍了以编程方式将模板列添加到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列值需要绑定到一个gridview编程为列(不是行)。例如,如果我的DAL返回10个值,则需要将这10个值显示为网格视图中的列作为标题文本,并将每列的第一行中的文本框用作数据输入。我知道我需要创建一个实现ITemplate接口并将其绑定到网格的类,但我不想为每个列进行此操作。有没有一种方法可以创建一个实现ITemplate的泛型类,这样我就可以将任何需要的控件放入它并绑定到网格?对于最后一列,我需要一个添加链接,它将添加输入的值。所有这些都可以通过声明方式很容易地完成,但我正在努力以编程方式完成这项工作。



感谢您的帮助。



编辑:我正在尝试在ASP.NET 4和C#中执行此操作。

解决方案

帮助:


I've a list of values that need to be bound to a gridview programmatically as columns (not rows). For example, if my DAL returns 10 values, I need to display these 10 values as columns in a gridview as header text and have a textbox in the first row for each column as data input. I understand I need to create a class that implements the ITemplate interface and bind it to grid but I do not want to do it for each column. Is there a way I can create a generic class which implements ITemplate so I can put whatever control I want in it and bind to grid? For the last column, I need an "Add" link which will add the values entered. All of this can be done very easily declaratively but I'm struggling to get this done programmatically.

Thanks for any help.

Edit: I'm trying to do this in ASP.NET 4 and C#.

解决方案

This may be helpful:

这篇关于以编程方式将模板列添加到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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