0

I have a DataGrid item on an aspx page. The columns are BoundColumns that are populated through a DataSource/DataBind from an Oracle query.

What I am trying to do is add a title attribute to each of the column headers

What I have is

<asp:datagrid id="DataGrid1" runat="server" OnItemCreated="DataGrid1_ItemCreated">

among other attributes

and then when the items are created I have a C#.net event trigger

protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e){

I have found out how to add the title attribute to a row, and even explicitly the Header row, but not how to parse out the individual headers

I have been using:

if(e.Item.Cells[0] = "&nbsp;"){
    e.Item.Attributes.Add("title", "Project Title";
}

I haven't yet found a way to access the text of the header, or the individual text value within the row. Any advice is appreciated, Thanks.

hrezs
  • 782
  • 1
  • 8
  • 23
  • 1
    Check Marc's answer [here](http://stackoverflow.com/questions/2486482/how-to-change-header-text-in-datagridview-in-code-c). – Brian May 16 '13 at 23:05
  • I did not get your question completely Do you want to access the header cells and change the texts inside them or you want to add an attribute to each cell of header or both ? – Kiarash May 17 '13 at 00:28
  • I want add an attribute to each cell of the header with the header cell contents. The problem is the columns are defined as BoundColumns, which do not take title as an attribute. I have sorta made my way around it by attaching the property on item creation. It looks like Marc's answer should help with getting the contents, I'll have to check it tomorrow. – hrezs May 17 '13 at 00:32

1 Answers1

0

here's what i did:

protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e){
    for(int i = 0; i < e.Item.Cells.Count; i++){
        e.Item.Cells[i].Attributes.Add("title", DataGrid1.Columns[i].HeaderText);
    }
}
hrezs
  • 782
  • 1
  • 8
  • 23