代碼如下
protected void Page_Load(object sender EventArgs e)
{
TemplateField mycustomField = new TemplateField(); //創建列實例
mycustomFieldShowHeader = true; // 設置屬性
LinkButton lb = new LinkButton();
lbText = Delete;
mycustomFieldHeaderTemplate = new GridViewTemplate(DataControlRowTypeHeader 刪除);
mycustomFieldItemTemplate = new GridViewTemplate(DataControlRowTypeDataRow lb);
TabelContentListGridViewColumnsAdd(mycustomField); //添加列到TabelContentListGridView控件
// 這種綁定翻頁會丟失數據
// 下面的綁定數據可以保持 不過也要清零列不然後出現很多重復列
// TabelContentListGVColumnsClear(); //清零列
// SystemWebUIWebControlsBoundField customField = new BoundField();
// customFieldDataField = dtColumns[i]ColumnName;
// customFieldHeaderText = dtColumns[i]ColumnName;
// customFieldItemStyleCssClass = dtColumns[i]ColumnName;
// TabelContentListGridViewColumnsAdd(customField);
}
From:http://tw.wingwit.com/Article/program/net/201311/12799.html