DataGridView标头名称更改 [英] DataGridView header name change

查看:117
本文介绍了DataGridView标头名称更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DataGridView中有SQL数据.我想更改DataGridView的标题文本,而又不影响数据库中的数据.

请帮助我.

I have SQL data in a DataGridView. I want to change the DataGridView''s header texts without affecting the data in the database.

Please help me.

推荐答案

使用您自己的GridView列,并可以分配gridview的Header文本.转到GridView的属性->列->添加列,然后将DataBound设置为DB列名称和标题文本属性.

并且不要忘记将gridview的AutoGeneratedColumns属性设置为false

或者,如果您想以编程方式设置标题,请使用以下代码:-
Use your own column of GridView and can assign the Header text of the gridview. Go to Properties of the GridView-->Columns-->Add the column and set the DataBound to the DB Column name and Header Text Property.

And Dont forget to set the AutoGeneratedColumns property to false of the gridview

Or if you want to set your header programmatically then use following code:-
GridView_Id.Columns[0].HeaderText = "HeaderName";
//This will change the GridView’s first column to "HeaderName



祝你好运.



Best of luck.


尝试一下:
Try this:
protected void grdSearchResult_RowDataBound(object sender, GridViewRowEventArgs e)
{
     if (e.Row.RowType == DataControlRowType.Header)
     {
        for (int i = 0; i < e.Row.Cells.Count; i++)
        {
            e.Row.Cells[i].Text = "your header name";
        }
     }
}


这篇关于DataGridView标头名称更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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