如何操作gridview中动态生成的模板列checkbox?
我在gridview中动态生成模板列,类型为checkbox,然后把后台数据库表中的数据对其进行绑定,代码如下:
private void setTemplateFields()
{
TemplateField templateField1 = new TemplateField();
templateField1.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "列1 ");
TemplateField templateField2 = new TemplateField();
templateField2.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "列2 ");
//将字段添加到GridView
GridView1.Columns.Add(templateField1);
GridView1.Columns.Add(templateField2);
}
//样板类产生器,以创建样板字段
public class GridViewTemplate : ITemplate
{
private DataControlRowType templateType;
private string columnName;
public GridViewTemplate(DataControlRowType type, string colname)
{
templateType = type;
columnName = colname;
}
public void InstantiateIn(System.Web.UI.Control container)
{
if (templateType == DataControlRowType.DataRow)
{
//创建样板字段外观
//TextBox txtEmployeeID = new TextBox();