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

Group header linkbutton

4 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paula
Top achievements
Rank 1
Paula asked on 13 Jul 2010, 08:31 PM
I have created a grid and it has group header controls that I create in the prerender event so that it will not be reset during postback.  I originally did it in the itemdatabound but it disappears during postback and since I need to access a dataitem value this was my only option but my problem now is that I cannot add the onclick handler.  Anyone have any iteas how I can do this? 

My group header current looks like ( Field_Value_Label_control  Add_New_Link_Button ) or as an example it would be (Computers  Add New Category) both of which have text from an sql database.

Any help would be appreciated.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Jul 2010, 10:28 AM
Hello Paula,

One suggestion is to create the GroupHeader control and attach onclick event in both ItemCreated and ItemDataBound event. Sample code is given below.

C#:
protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e)
    {
         if (e.Item is GridGroupHeaderItem)
          {
               GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
               LinkButton linkBtn = new LinkButton();
               item.DataCell.Controls.Add(linkBtn);
               linkBtn.ID = "LinkButton1";
               linkBtn.Text = item.DataCell.Text;
               linkBtn.Click += new EventHandler(linkBtn_Click);
           }
    }
 
  protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridGroupHeaderItem)
        {
            GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;
            LinkButton linkBtn = new LinkButton();
            item.DataCell.Controls.Add(linkBtn);
            linkBtn.ID = "LinkButton1";
            linkBtn.Click += new EventHandler(linkBtn_Click);
        
    }

Thanks,
Princy.
0
Paula
Top achievements
Rank 1
answered on 16 Jul 2010, 04:12 PM
Unfortunately this doesn't work, all the values are lost in postback which is why it has to be in the prerender event. 

0
Paula
Top achievements
Rank 1
answered on 16 Jul 2010, 05:03 PM
To get around this I'm just going to use nested views.  I should have did this to begin with.

Thanks for trying to help.
0
Enigma
Top achievements
Rank 1
answered on 01 Nov 2010, 07:57 AM
I had a very similar problem where I wanted to add a LinkButton to the group header that would enter edit mode for all items in that group. I was/am using code very similar to that suggested by Princy. After much debugging, playing and searching I found the MasterTableView.GroupLoadMode property, by setting this property to 'Client' all by problems went the way of the dinosaurs.
Tags
Grid
Asked by
Paula
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Paula
Top achievements
Rank 1
Enigma
Top achievements
Rank 1
Share this question
or