January 15, 2014

Change header text of columns in a DataGrid ASP.NET C#



I was researching how to change the header text of columns in a datagrid in ASP.NET.
I found several ways to make a GridView, for any example of how to do it in a DataGrid.
After much research comes to this, and it works. This also serves to the autogenerating columns 

We have to use the ItemDataBound event

The example below, if you know other ways please comment.


protected void theDataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Header)
            {
                try
                {
                    e.Item.Cells[1].Text = "header 1";
                    e.Item.Cells[2].Text = "header 2";
                    e.Item.Cells[3].Text = "header 3";
                    e.Item.Cells[4].Text = "header 4";
                    e.Item.Cells[5].Text = "header 5";
                    e.Item.Cells[6].Text = "header 5";
                }
                catch { }
            }
        }
see also

Force downloading a file from C #

Ditulis Oleh : Angelo Hari: 10:23 AM Kategori:

0 comentarios:

Post a Comment