如何在code-后面添加一个GridView列? [英] How to add a GridView Column on code-behind?

查看:106
本文介绍了如何在code-后面添加一个GridView列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一列添加到GridView,在ASP.NET 2.0

  gridViewPoco.Columns.Add(...)

不过,我不能找到合适的选项。我想等效于以下内容:

 < ASP:BoundField的>
< ASP:的TemplateField>


解决方案

例如;

 保护无效Btn_AddCol_Click(对象发件人,EventArgs的发送)
{
    模板列TF =新的TemplateField();
    tf.HeaderTemplate =新GridViewLabelTemplate(DataControlRowType.Header,COL1,的Int32);
    tf.ItemTemplate =新GridViewLabelTemplate(DataControlRowType.DataRow,COL1,的Int32);
    MyGridView.Columns.Add(TF);
}


  • 定义新的 模板列

  • 设置列标题名称( COL1 )和式(的Int32

  • 将列值(的Int32

  • 这个字段添加到您的的GridView

I'm trying to add a column to a GridView, in ASP.NET 2.0

gridViewPoco.Columns.Add(...)

However, i cant find the right option. I'd like equivalents to the following:

<asp:BoundField>
<asp:TemplateField>

解决方案

For example;

protected void Btn_AddCol_Click(object sender, EventArgs e)
{
    TemplateField tf = new TemplateField();
    tf.HeaderTemplate = new GridViewLabelTemplate(DataControlRowType.Header, "Col1", "Int32");
    tf.ItemTemplate = new GridViewLabelTemplate(DataControlRowType.DataRow, "Col1", "Int32");
    MyGridView.Columns.Add(tf);
}

  • Define new TemplateField
  • Set the column header name (Col1) and type (Int32)
  • Set the column value type (Int32)
  • Add this field to your Gridview

这篇关于如何在code-后面添加一个GridView列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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