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

Obtain GroupHeader Value

2 Answers 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gino Suarez
Top achievements
Rank 1
Gino Suarez asked on 09 Dec 2009, 10:06 PM
Hi Telerik experts,

Can you say me how to get the value of a groupheader, actually i can get the text based on your sample, also i can get the groupindex, but i can't get the value set into  FieldName="SubDiarioID"
protected void tk_Grid_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridGroupHeaderItem groupHeader in tk_Grid.MasterTableView.GetItems(GridItemType.GroupHeader)) 
        { 
            string strtxt = groupHeader.DataCell.Text; // accessing the groupheader text    
            string strGroupIndex = groupHeader.GroupIndex; 
            LinkButton hyperlnk = new LinkButton(); // creting new link    
            hyperlnk.Text = strtxt.Substring(8,strtxt.Length-8); 
            hyperlnk.CssClass = "gridtextbold"
            hyperlnk.Attributes.Add("OnClick", "return AbreVentana('ConsolidadoDiarioAuxiliar.aspx','Consolidado');"); 
            groupHeader.DataCell.Controls.Clear(); 
            groupHeader.DataCell.Controls.Add(hyperlnk); // adding link to the groupheader       
        }   
    } 

<GroupByExpressions > 
                                                <telerik:GridGroupByExpression >  
                                                    <GroupByFields >                                                                                                         
                                                        <telerik:GridGroupByField   FieldName="SubDiarioID"  FormatString="{0:g}" />                                                         
                                                    </GroupByFields> 
                                                    <SelectFields> 
                                                        <telerik:GridGroupByField FieldName="BESubDiarios.NombreSubDiario" HeaderText="Cuenta" /> 
                                                    </SelectFields> 
                                                     
                                                </telerik:GridGroupByExpression> 
                                            </GroupByExpressions> 
                                           <GroupHeaderItemStyle HorizontalAlign="Left" CssClass="gridtext"  /> 



2 Answers, 1 is accepted

Sort by
0
Gino Suarez
Top achievements
Rank 1
answered on 09 Dec 2009, 10:34 PM
i find and answer in the forum, thanks at all

protected void tk_Grid_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
 
        if (e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item; 
            System.Data.DataRowView groupDataRow = (System.Data.DataRowView)e.Item.DataItem; 
            item.DataCell.Text = groupDataRow["SubDiarioID"].ToString(); 
 
             
        } 
 
    } 

Best Regards
Gino
0
Princy
Top achievements
Rank 1
answered on 10 Dec 2009, 11:26 AM
Hello Gino,

When you set the groupheader text in the ItemDataBound event of the grid, the text value does not persist on postbacks or grid rebinding. So a better option would be to set the text in the PreRender event of the grid as shown below:
c#:
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridGroupHeaderItem headerItem in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)) 
        { 
            DataRowView dataRow = (DataRowView)headerItem.DataItem; 
            headerItem.DataCell.Text = dataRow["SubDiarioID"].ToString(); 
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Gino Suarez
Top achievements
Rank 1
Answers by
Gino Suarez
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or