Modify Datagrid HeaderTemplate through code

D

Dave A.

I have an editable datagrid with HeaderTemplates that have to be written
through code, with data from the database. I can only find code to add new
columns and modify text. Is there any way to be able to modify existing
HeaderTemplate.Text values?


thanks
Dave A.
 
D

Dave A.

How is this function called - _grid_RowDataBound(), and will I need to loop
through the HeaderTemplate row to modify the text? Instead of looping through
the whole row, can I refer to the column index?

Dave A.
 
D

Dave A.

Thanks for the tip. I modified your code for the datagrid. This is what worked.

<asp:DataGrid id="DGProducts"
runat="server"
Cellpadding="4" Cellspacing="0" Width="800"
BorderStyle="solid" BorderColor="black" BorderWidth="1"
AlternatingItemStyle-BackColor="palegoldenrod"
ItemStyle BackColor="beige"
HeaderStyle-CssClass="productsHead"
Font-Size="10"
AutoGenerateColumns="false"
OnEditCommand="DGProducts_Edit"
OnCancelCommand="DGProducts_Cancel"
OnUpdateCommand="DGProducts_Update"
OnItemDataBound="Item_Bound">


Public Sub Item_Bound(sender As Object, e As DataGridItemEventArgs)

Dim itemType As ListItemType
Dim intCell As TableCell

itemType = CType(e.Item.ItemType, ListItemType)

If (itemType = ListItemType.Header) Then
intCell = CType(e.Item.Controls(4), TableCell)
intCell.Text = "fy text"
End If
End Sub

thanks,
Dave A.
 
B

Brock Allen

The DataGrid (again in 1.1, which is a bit different than my 2.0 sample)
has a ItemDataBound event. This will get called after each row (including
the the header) is full created and populated with data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top