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

[Solved] Grouping without FieldName property

3 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alper Ozgur
Top achievements
Rank 1
Alper Ozgur asked on 15 Mar 2010, 10:55 AM
Hi;
In a RadGrid i had 3 TemplateColumn as below... I'm setting the values of Labels in TemplateColumns at Item_Databound function. For that reason the columns don't have FieldNames. When i try to activate the GroupBy property i can't do that due to FieldName's being empty. How can i solve this problem?

 

            <telerik:RadGrid ID="ctlNitelikGrid" runat="server" AllowCustomPaging="true" AllowPaging="true" 
                AllowSorting="true" Skin="Office2007" AllowAutomaticDeletes="True" AutoGenerateDeleteColumn="True" 
                OnItemDataBound="ctlNitelikGrid_ItemDataBound" ShowGroupPanel="False">  
                <MasterTableView AutoGenerateColumns="false">  
                    <GroupByExpressions> 
                        <telerik:GridGroupByExpression> 
                            <SelectFields> 
                                <telerik:GridGroupByField HeaderText="Sektör"/>  
                            </SelectFields> 
                        </telerik:GridGroupByExpression> 
                    </GroupByExpressions> 
                    <Columns> 
                        <telerik:GridTemplateColumn HeaderText="Sektör" UniqueName="Sektor">  
                            <ItemTemplate> 
                                <asp:Label ID="lblNitelikSektor" runat="server" CssClass="itemsLabel"></asp:Label> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn HeaderText="Alan" UniqueName="Alan">  
                            <ItemTemplate> 
                                <asp:Label ID="lblNitelikAlan" runat="server" CssClass="itemsLabel"></asp:Label> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                        <telerik:GridTemplateColumn HeaderText="Nitelik" UniqueName="Nitelik">  
                            <ItemTemplate> 
                                <asp:Label ID="lblNitelikNitelik" runat="server" CssClass="itemsLabel"></asp:Label> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                    </Columns> 
                </MasterTableView> 
            </telerik:RadGrid> 

 

 


and the code for bound

 

protected void ctlNitelikGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)   
{  
Control ctl = e.Item.FindControl("lblNitelikSektor");   
Control ctl2 = e.Item.FindControl("lblNitelikAlan");   
Control ctl3 = e.Item.FindControl("lblNitelikNitelik");   
if (ctl != null && ctl2 != null && ctl3 != null)   
{  
Label label = (Label)ctl;   
Label label2 = (Label)ctl2;   
Label label3 = (Label)ctl3;   
object obj1 = new object();   
object obj2 = new object();   
object obj3 = DataBinder.GetPropertyValue(e.Item.DataItem, "PRM1");   
if (obj3 != null && !Convert.IsDBNull(obj3))   
{  
label3.Text = GetParameter(Convert.ToDecimal(obj3), "VAL3").ToString();  
obj2 = (object)GetParameter(Convert.ToDecimal(obj3), "U3");   
}  
if (obj2 != null && !Convert.IsDBNull(obj2))   
{  
 
label2.Text = GetParameter(Convert.ToDecimal(obj2), "VAL2").ToString();   
obj1 = (object)GetParameter(Convert.ToDecimal(obj2), "U2");   
}  
if (obj1 != null && !Convert.IsDBNull(obj1))   
label.Text = GetParameter(Convert.ToDecimal(obj1), "U1").ToString();   
}  
}  
 

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 15 Mar 2010, 01:05 PM
Hello Alper,

Have you considered specifying GroupByExpression value for your template columns either declaratively or programmatically as explained in the bottom section of this documentation topic? Thus if you have fields in the grid source with names "Alan", "Nitelik", etc. you can define these group expressions as follows:

<telerik:RadGrid ID="ctlNitelikGrid" runat="server" AllowCustomPaging="true" AllowPaging="true"  
                AllowSorting="true" Skin="Office2007" AllowAutomaticDeletes="True" AutoGenerateDeleteColumn="True"  
                OnItemDataBound="ctlNitelikGrid_ItemDataBound" ShowGroupPanel="False">   
                <MasterTableView AutoGenerateColumns="false">   
                    <GroupByExpressions>  
                        <telerik:GridGroupByExpression>  
                            <SelectFields>  
                                <telerik:GridGroupByField HeaderText="Sektör"/>   
                            </SelectFields>  
                        </telerik:GridGroupByExpression>  
                    </GroupByExpressions>  
                    <Columns>  
                        <telerik:GridTemplateColumn HeaderText="Sektör" UniqueName="Sektor" GroupByExpression="Sektör Group By Sektör">   
                            <ItemTemplate>  
                                <asp:Label ID="lblNitelikSektor" runat="server" CssClass="itemsLabel"></asp:Label>  
                            </ItemTemplate>  
                        </telerik:GridTemplateColumn>  
                        <telerik:GridTemplateColumn HeaderText="Alan" UniqueName="Alan" GroupByExpression="Alan Group By Alan">   
                            <ItemTemplate>  
                                <asp:Label ID="lblNitelikAlan" runat="server" CssClass="itemsLabel"></asp:Label>  
                            </ItemTemplate>  
                        </telerik:GridTemplateColumn>  
                        <telerik:GridTemplateColumn HeaderText="Nitelik" UniqueName="Nitelik" GroupByExpression="Nitelik Group By Nitelik">   
                            <ItemTemplate>  
                                <asp:Label ID="lblNitelikNitelik" runat="server" CssClass="itemsLabel"></asp:Label>  
                            </ItemTemplate>  
                        </telerik:GridTemplateColumn>  
                    </Columns>  
                </MasterTableView>  
            </telerik:RadGrid>  

Best regards,
Sebastian
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Alper Ozgur
Top achievements
Rank 1
answered on 15 Mar 2010, 01:16 PM
I had looked to the documentation that you gave below. But the problem is the values that fills the Labels are not in the datasource. For that reason i can't reach their fieldnames.. There are only labels in templatecolumns. If i had to add those fields to the datasource than i must create a new datatable. I only need to know is there anyway to generate group by functionality without using fieldname.
0
Accepted
Sebastian
Telerik team
answered on 15 Mar 2010, 01:41 PM
Hello Alper,

This is not possible since the grid is data-bound control and can apply grouping only for fields present in its source. Consider exposing the necessary data as part of the grid data source to achieve your goal.

Kind regards,
Sebastian
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Alper Ozgur
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Alper Ozgur
Top achievements
Rank 1
Share this question
or