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

dynamically regroup grid base on dropdown

1 Answer 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roland
Top achievements
Rank 1
Roland asked on 30 Oct 2008, 04:52 PM
Hello,
 
 I'm having some difficulties implemention a  grid regroup based on user's selection  in a dropdown control.
 Basically, I'll like my users to select "group by Agency" or "by client"  based on the selection the make in a dropdown box.

 in my dropdown event handler, I'll like to change the grouping. the default group is by Agency.
 
  below is my grid structure.

/*************************************/

<telerik:radgrid id="gridWorks"
DataSourceID="getWorks"
runat="server"
ShowStatusBar="true"              
gridlines="Horizontal"
skin="WebBlue"
AllowSorting="true"
ShowGroupPanel="false"
AutoGenerateColumns="false"                        
OnUpdateCommand="gridWorks_UpdateCommand"
OnDeleteCommand="gridWorks_DeleteCommand"
OnInsertCommand="gridWorks_InsertCommand"
PageSize="50" AllowAutomaticDeletes="True" OnItemCommand="gridWorks_ItemCommand" >

<MasterTableView GroupLoadMode="Client"  CommandItemDisplay="TopAndBottom" DataKeyNames="workID,Title" AllowPaging="True" AllowSorting="False" DataSourceID="getWorks">

<Columns>
<telerik:GridBoundColumn DataField="Title" HeaderText="Title" ReadOnly="True" SortExpression="Agency" UniqueName="Title"/>
<telerik:GridBoundColumn DataField="Client" HeaderText="Client" ReadOnly="True" SortExpression="client" UniqueName="Client"/>
<telerik:GridBoundColumn DataField="SiteStatus" HeaderText="Site Status" ReadOnly="True"  UniqueName="SiteStatus"/>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Update" ImageUrl="../Images/ICEdit.gif" HeaderText="Edit" UniqueName="column" />
<telerik:GridButtonColumn ConfirmText="Are you sure you want to delete this Work?\n Items are none recoverable once deleted!"  HeaderText="Delete" CommandName="Delete" ButtonType="ImageButton" ImageUrl="../Images/ICTrash.gif" Text="Delete" UniqueName="Delete"/>
<telerik:GridBoundColumn DataField="Modified" HeaderText="Last Modified" ReadOnly="True"  UniqueName="Last Modified"/>

</Columns>

<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>

<GroupByExpressions>
<telerik:GridGroupByExpression>
<SelectFields>
<telerik:GridGroupByField FieldName="Agency" FieldAlias="Agency" />

</SelectFields>
<GroupByFields>
<telerik:GridGroupByField  FieldName="Agency" FieldAlias="Agency"/>
</GroupByFields>

</telerik:GridGroupByExpression>
</GroupByExpressions>


/********************/

 your help is much appreciated.
-roland

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 31 Oct 2008, 04:12 AM
Hi Roland,

Try the following code snippet to achieve the desired scenario.

ASPX:
<asp:DropDownList ID="DropDownList1" AutoPostBack="true"  runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
              <asp:ListItem Text="Agency" ></asp:ListItem> 
               <asp:ListItem Text="Client" ></asp:ListItem> 
            </asp:DropDownList> 

CS:
 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        RadGrid1.MasterTableView.GroupByExpressions.Clear(); 
        string strGrouptxt = DropDownList1.SelectedItem.Text; 
 
        GridGroupByExpression expression = new GridGroupByExpression(); 
        GridGroupByField gridGroupByField = new GridGroupByField(); 
      
        gridGroupByField.FieldName = strGrouptxt
        gridGroupByField.HeaderText = strGrouptxt
        expression.SelectFields.Add(gridGroupByField); 
        expression.GroupByFields.Add(gridGroupByField); 
 
        RadGrid1.MasterTableView.GroupByExpressions.Add(expression); 
 
        RadGrid1.Rebind(); 
    } 


Hope this helps..
Shinu.
Tags
Grid
Asked by
Roland
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or