Modify Datagrid HeaderTemplate through code

Discussion in 'ASP .Net Web Controls' started by Dave A., Aug 14, 2005.

  1. Dave A.

    Dave A. Guest

    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.
     
    Dave A., Aug 14, 2005
    #1
    1. Advertising

  2. Dave A.

    Brock Allen Guest

    You can do it once the row is created. I do this in a sample here (it's using
    the 2.0 GridView, but the concept is same for v1.1 DataGrid):

    http://staff.develop.com/ballen/blog/PermaLink.aspx?guid=c35c43f6-5686-40ee-9752-8095a848d821

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > 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.
     
    Brock Allen, Aug 15, 2005
    #2
    1. Advertising

  3. Dave A.

    Dave A. Guest

    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.

    "Brock Allen" wrote:

    > You can do it once the row is created. I do this in a sample here (it's using
    > the 2.0 GridView, but the concept is same for v1.1 DataGrid):
    >
    > http://staff.develop.com/ballen/blog/PermaLink.aspx?guid=c35c43f6-5686-40ee-9752-8095a848d821
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > 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.

    >
    >
    >
    >
     
    Dave A., Aug 15, 2005
    #3
  4. Dave A.

    Dave A. Guest

    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.
    "Brock Allen" wrote:

    > You can do it once the row is created. I do this in a sample here (it's using
    > the 2.0 GridView, but the concept is same for v1.1 DataGrid):
    >
    > http://staff.develop.com/ballen/blog/PermaLink.aspx?guid=c35c43f6-5686-40ee-9752-8095a848d821
    >
    > -Brock
    > DevelopMentor
    > http://staff.develop.com/ballen
    >
    >
    >
    > > 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.

    >
    >
    >
    >
     
    Dave A., Aug 16, 2005
    #4
  5. Dave A.

    Brock Allen Guest

    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.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > 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.
    >
    > "Brock Allen" wrote:
    >
    >> You can do it once the row is created. I do this in a sample here
    >> (it's using the 2.0 GridView, but the concept is same for v1.1
    >> DataGrid):
    >>
    >> http://staff.develop.com/ballen/blog/PermaLink.aspx?guid=c35c43f6-568
    >> 6-40ee-9752-8095a848d821
    >>
    >> -Brock
    >> DevelopMentor
    >> http://staff.develop.com/ballen
    >>> 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.
     
    Brock Allen, Aug 16, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SamIAm
    Replies:
    1
    Views:
    4,557
    Bipin Joshi [MVP]
    Jun 26, 2003
  2. Vijaya
    Replies:
    2
    Views:
    2,650
    Vijaya
    Nov 13, 2003
  3. Cheng
    Replies:
    2
    Views:
    9,373
    dany7487
    Nov 14, 2007
  4. Ashish Sharma

    DataGrid HeaderTemplate Question

    Ashish Sharma, Apr 14, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    405
    Ashish Sharma
    Apr 14, 2004
  5. JoNa SuperGold

    controlling button in headertemplate datagrid

    JoNa SuperGold, Apr 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,139
Loading...

Share This Page