加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何在代码隐藏中添加一个GridView列?

发布时间:2020-12-15 18:05:32 所属栏目:百科 来源:网络整理
导读:我正在ASP.NET 2.0中为GridView添加一列 gridViewPoco.Columns.Add(...) 但是,我找不到正确的选项.我想要等同于以下内容: asp:BoundFieldasp:TemplateField 解决方法 例如; protected void Btn_AddCol_Click(object sender,EventArgs e){ TemplateField tf
我正在ASP.NET 2.0中为GridView添加一列
gridViewPoco.Columns.Add(...)

但是,我找不到正确的选项.我想要等同于以下内容:

<asp:BoundField>
<asp:TemplateField>

解决方法

例如;
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,"Int32");
    MyGridView.Columns.Add(tf);
}

>定义新的TemplateField>设置列标题名(Col1)和类型(Int32)>设置列值类型(Int32)>将此字段添加到您的Gridview

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读