This is a migrated thread and some comments may be shown as answers.

Adding LinkButton to GroupHeaderItem

3 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mary
Top achievements
Rank 1
mary asked on 20 Aug 2008, 01:29 PM

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

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Aug 2008, 06:48 AM
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
0
mary
Top achievements
Rank 1
answered on 21 Aug 2008, 08:20 AM
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?

0
Kiara
Top achievements
Rank 1
answered on 22 Aug 2008, 02:05 PM
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
Tags
Grid
Asked by
mary
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
mary
Top achievements
Rank 1
Kiara
Top achievements
Rank 1
Share this question
or