Change header text of columns in a GridView

前端 未结 6 605
天涯浪人
天涯浪人 2020-12-08 14:26

I have a GridView which i programmatically bind using c# code. The problem is, the columns get their header texts directly from Database, which can look odd when presented o

6条回答
  •  旧巷少年郎
    2020-12-08 14:55

    Better to find cells from gridview instead of static/fix index so it will not generate any problem whenever you will add/remove any columns on gridview.

    ASPX:

    
        
            
        
    
    

    CS:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                if (string.Compare(e.Row.Cells[i].Text, "Date", true) == 0)
                {
                    e.Row.Cells[i].Text = "Created Date";
                }
            }
        }
    }
    

提交回复
热议问题