Adding LinkButton to GroupHeaderItem

4 posts, 0 answers
  1. mary
    mary avatar
    34 posts
    Member since:
    Apr 2008

    Posted 20 Aug 2008 Link to this post

    Hi
    I'm trying to add text description and linkbuttons to the groupdheaderitem of a grid.  I've added the controls in both ItemDataBound and ItemCreated grid events.   As per the samples I'm using 

    DataRowView groupDataRow = e.Item.DataItem as DataRowView;

    to access the data for the row, but this is not available on postback and I can't find another way to get the data for the row. 
    I can't access the DatakeyValues in ItemCommand events as the itemindex isn't set on the group header.
    Is there another way to customize the contents of the group header to include buttons that will postback correctly and allow me to identify the data row for the event?

    I'm using the latest version of the grid. 

    Thanks

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Aug 2008 Link to this post

    Hi Mary,

    Try the following code snippet to add linkbutton in the GroupHeader.

    CS:
     protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
        { 
            if (e.Item is GridGroupHeaderItem) 
            { 
                GridGroupHeaderItem header = (GridGroupHeaderItem)e.Item; 
                LinkButton lnkbtn = new LinkButton(); 
                lnkbtn.ID = "Button1"
                lnkbtn.Text = "Click"
                header.DataCell.Controls.Add(lnkbtn); 
            } 
            
        } 
         
        protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridGroupHeaderItem) 
            { 
                GridGroupHeaderItem header = (GridGroupHeaderItem)e.Item; 
                LinkButton lnkbtn = new LinkButton(); 
                lnkbtn.ID = "Button1"
                lnkbtn.Text = "Click"
                lnkbtn.Click += new EventHandler(lnkbtn_Click); 
                header.DataCell.Controls.Add(lnkbtn); 
            } 
        } 
        void lnkbtn_Click(object sender, EventArgs e) 
        { 
            LinkButton lnkbtn = (LinkButton)sender; 
            GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)lnkbtn.NamingContainer; 
     
        } 
        
     


    Thanks
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. mary
    mary avatar
    34 posts
    Member since:
    Apr 2008

    Posted 21 Aug 2008 Link to this post

    Thanks for the reply but it does not answer my question.

    I am adding the button to the groupheader and detecting the postback but the data for the row is not consistently available.  On postback the datarowview is null

    DataRowView groupDataRow = e.Item.DataItem as DataRowView;

    Is there another way to get the data for the row on postback?

  5. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 22 Aug 2008 Link to this post

    The data in the grid rows should be bound and available inside the ItemDataBound handler of the control. I think that this mimics the behavior of the standard MS GridView control. However, you should be aware that when adding controls inside the group header you may lose the data in it - found this info in this code library thread.

    Kiara
Back to Top