关于后台生成的模板列的数据绑定问题

动态产生模版列参考:
public class DataGridTemplate : ITemplate
{
?? ListItemType templateType;
?? string columnName;
??
?? public DataGridTemplate(ListItemType type, string colname)
?? {
????? templateType = type;
????? columnName = colname;
?? }

?? public void InstantiateIn(System.Web.UI.Control container)
?? {
????? Literal lc = new Literal();
????? switch(templateType)
????? {
???????? case ListItemType.Header:
??????????? lc.Text = "" + columnName + "";
??????????? container.Controls.Add(lc);
??????????? break;
???????? case ListItemType.Item:
??????????? lc.Text = "Item " + columnName;
??????????? container.Controls.Add(lc);
??????????? break;
???????? case ListItemType.EditItem:
??????????? TextBox tb = new TextBox();
??????????? tb.Text = "";
??????????? container.Controls.Add(tb);
??????????? break;
???????? case ListItemType.Footer:
??????????? lc.Text = "" + columnName + "";
??????????? container.Controls.Add(lc);
??????????? break;
????? }
?? }
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingtemplatesprogrammaticallyindatagridcontrol.asp
邦定字段例:
lc.DataBinding += new System.EventHandler(BindLabelColumn)

...

private void BindLabelColumn(object sender, EventArgs e)
{
??????Label lbl = (Label)sender;
??????DataGridItem Container = (DataGridItem)lbl.NamingContainer;
??????lbl.Text = DataBinder.Eval(Container.DataItem, Field1);
}

阅读更多
个人分类: WebForm
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭