请教,怎样给动态生成的模板列绑定数据,谢谢!!!!!
我的程序如下:
//根据数据表项目的记录动太生成GridView的列
private void CreateGridviewColumns()
{
gvUnderGraduateList.Columns.Clear();
foreach (DataRow dr in dsProject.Tables[0].Rows)
{
TemplateField tf = new TemplateField();
tf.ShowHeader = true;
tf.HeaderText = dr[2].ToString();
tf.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
tf.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, dr[2].ToString(), (800 / dsProject.Tables[0].Rows.Count));
gvUnderGraduateList.Columns.Add(tf);
}
gvUnderGraduateList.DataBind();
}
//模板类
public class GridViewTemplate : ITemplate
{
private DataControlRowType templateType;
private string columnName;
private int tbWidth;
public GridViewTemplate(DataControlRowType type, string colname,int pWidth)
{
templateType = type;
columnName = colname;
tbWidth = pWidth;
}
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.Header:
Literal lc = new Literal();