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

how to keep customized controls inside groupbyexpressions.

1 Answer 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sudheer
Top achievements
Rank 2
sudheer asked on 23 Feb 2009, 08:11 AM
Hi

How to keep customized controls inside  <GroupByExpressions> in rad oulookstyle grid. i followed the below demo example
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/webmail/defaultcs.aspx

in which right side to to received header i want to keep one button . i tried using commanditemtemplate  but no chance, how to keep

Any help appreciable.


1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Feb 2009, 09:06 AM
Hello Sudheer,

You can add a table to the group header and add the button and the header text into the table cells, in the ItemDataBound and ItemCreated events of the grid. You can also set the click event handler of the button in the ItemCreated event. Check out the code below:
cs:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
       if (e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item; 
            string strtxt = groupHeader.DataCell.Text; 
            Button btn = new Button(); 
            btn.ID = "Button1"
            btn.Text = "Button"
            btn.Click += new EventHandler(btn_Click); 
            Label lbl = new Label(); 
            lbl.ID = "Label"
            
            Table table = new Table(); 
            TableRow row = new TableRow(); 
            table.Rows.Add(row); 
            TableCell cell1 = new TableCell(); 
            cell1.Controls.Add(lbl); 
            TableCell cell2 = new TableCell(); 
            cell2.Controls.Add(btn); 
            table.Rows[0].Cells.Add(cell1); 
            table.Rows[0].Cells.Add(cell2); 
 
            groupHeader.DataCell.Controls.Add(table); 
        } 
     } 
 
void btn_Click(object sender, EventArgs e) 
    {         
         
    } 
        
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
       if(e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)e.Item; 
            string strtxt = groupHeader.DataCell.Text; 
            Button btn = new Button(); 
            btn.ID = "Button1"
            btn.Text = "Button"
            Label lbl = new Label(); 
            lbl.ID = "Label";             
            lbl.Text = strtxt
 
            Table table = new Table(); 
            TableRow row = new TableRow(); 
            table.Rows.Add(row); 
            TableCell cell1 = new TableCell(); 
            cell1.Controls.Add(lbl); 
            TableCell cell2 = new TableCell(); 
            cell1.Controls.Add(btn); 
            table.Rows[0].Cells.Add(cell1); 
            table.Rows[0].Cells.Add(cell2); 
 
            groupHeader.DataCell.Controls.Add(table); 
        } 
      }          

Thanks
Princy.
Tags
Grid
Asked by
sudheer
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or