Radgrid Group By problem

5 posts, 1 answers
  1. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 18 Oct 2011 Link to this post

    Hi Team,
    I have a hierarchical radgrid (find attached image.) and a button outside the radgrid.

    When I select some of d rows of grid, i should get the GroupID as well as its corresponding GroupItems' ID

    AS in image, When I select rows under the group "Coimbator", I should get ID of "Coimbator" as well as IDs of rows selecetd under "Coimbator"..

    Here is my aspx side. :

    <tr>
                        <td style="width:100%" colspan="3">
                            <telerik:RadGrid ID="rgGiroPayments" runat="server" OnNeedDataSource="rgGiroPayments_NeedDataSource" AllowMultiRowSelection="true">
                                <MasterTableView>
                                    <GroupByExpressions>
                                        <telerik:GridGroupByExpression>
                                            <SelectFields>
                                                <telerik:GridGroupByField FieldName="EntityKeyName" FieldAlias="Vendor" />
                                            </SelectFields>
                                            <GroupByFields>
                                                <telerik:GridGroupByField FieldName="EntityKeyName" FieldAlias="Vednor" />
                                            </GroupByFields>
                                        </telerik:GridGroupByExpression>
                                    </GroupByExpressions>
                                    <Columns>
                                        <telerik:GridBoundColumn DataField="AP_InvoiceID" HeaderText="AP_InvoiceID" Display="false" UniqueName="AP_InvoiceID">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="InvoiceNo" HeaderText="Invoice #" DataType="system.string"
                                            UniqueName="InvoiceNo" FilterControlWidth="75%" SortExpression="InvoiceNo"
                                            AutoPostBackOnFilter="true" CurrentFilterFunction="Contains">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="InvoiceDate" HeaderText="Date" FilterControlWidth="75%"
                                            UniqueName="InvoiceDate" DataFormatString="{0:d}" AutoPostBackOnFilter="true"
                                            CurrentFilterFunction="Contains">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="EntityID" HeaderText="EntityID" Display="false" UniqueName="EntityID">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="EntityIKeyD" HeaderText="EntityIKeyD" Display="false" UniqueName="EntityIKeyD">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="EntityKeyName" FilterControlWidth="75%" HeaderText="EntityKeyName"
                                            UniqueName="EntityKeyName" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" Display="false">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="InvoiceCurrencyName" HeaderText="Currency"
                                            UniqueName="InvoiceCurrencyName" FilterControlWidth="50%" AutoPostBackOnFilter="true"
                                            CurrentFilterFunction="Contains" Display="false">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CurrencySymbol" HeaderText="Currency"
                                            UniqueName="CurrencySymbol" FilterControlWidth="50%" AutoPostBackOnFilter="true"
                                            CurrentFilterFunction="Contains">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="InvoiceAmount" HeaderText="Amount" UniqueName="InvoiceAmount"
                                            FilterControlWidth="50%" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="BalanceAmount" HeaderText="Due Amount" UniqueName="BalanceAmount"
                                            AutoPostBackOnFilter="true" CurrentFilterFunction="Contains">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridClientSelectColumn UniqueName="Select">
                                        </telerik:GridClientSelectColumn>
                                    </Columns>
                                </MasterTableView>
                                <ClientSettings Selecting-AllowRowSelect="true"></ClientSettings>
                            </telerik:RadGrid>
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                            <asp:Button ID="btnPayment" runat="server" Text="Make Payment" OnClick="btnPayment_Click" />
                        </td>
                    </tr>

    Could you plz help me out ???

    Regards,
    Lok..
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Oct 2011 Link to this post

    Hello Lokesh,

    Try the following code snippet to get the ID on selecting the row. .
    C#:
    protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
     if (e.CommandName == "RowClick")
     {
       string value = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ColUniqueName"].ToString();
     }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 19 Oct 2011 Link to this post

    Hello Princy,
    I am not using Row_Click event of the grid.
    So whatever I want to achieve is on the Button_Click event (outside the grid).

    Here is what happens on Button_Click event when I select the rows randomly from any group.
    (I select a row from 2nd group, then from 1st group and again from 2nd group. So total 3 rows are selected from two different groups .)

    1. If I select row from 2nd group, initialy I get group index as 2 as my first row selected is from 2nd group.
    2 Then I get group index as 1 as my 2nd row selected is from 1st group.
    3 and here again i get group index as 2 as my last row selected is from 2nd group.

    What I want is, I should be able to get the collection of group index and row index
    Group        Rows
    1                1
    2                2

    If I select rows sequentially, i.e. first from first group and then from second group and then from third group and so on, I get this collection with no problem.
    But If I select the rows randomly from any group, its not possible.
     
    here is my Button_Click event
    string gropuindex = item.GroupIndex.Split('_')[0];
                       int CrntIndex = int.Parse(gropuindex);
                       int VendorsID = int.Parse(item["EntityKeyID"].Text);
                       if (CrntIndex == PrvIndex)
                       {
                           int VendorID = int.Parse(item["EntityKeyID"].Text);
                           InvoiceIDList = InvoiceIDList + item["AP_InvoiceID"].Text + ",";
                           PrvIndex = CrntIndex;
                           PrvVendorID = VendorsID;
                           VendorAmt = VendorAmt + double.Parse(item["InvoiceAmount"].Text);
                       }
                       else
                       {
                           AccPaymentsDA.GenerateGiroPayment(PrvVendorID, InvoiceIDList, int.Parse(rcbOrganization.SelectedValue), int.Parse(rcbCostCenter.SelectedValue), int.Parse(rcbBankAccount.SelectedValue), mCurrencyID, mCalendarPeriodID,VendorAmt);
                           InvoiceIDList = GlobalConstants.BLANK;
                           InvoiceIDList = item["AP_InvoiceID"].Text + ",";
                           PrvIndex = CrntIndex;
                           PrvVendorID = VendorsID;
                       }

    I hope you have understand my issue.
    Waiting for reply.

    Lok..
  5. Answer
    Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 24 Oct 2011 Link to this post

    Hello Lokesh,

    Have you tried using the SelectedIndexes/Items collection of the RadGrid control?
    These collections are populated with the indexes/items in the ored they are selected. If you decide to try this, you could set the field that you are grouping by as a DataKeyName, and when you loop through the selected items, you could access the DataKeyValue of the grouped item and use it to differentiate between the groups.

    Kind regards,
    Tsvetina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  6. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 24 Oct 2011 Link to this post

    Hi Tsvetina ,
    I tried that way also.. It works..
    Thanks for your respons.

    Regards,
    Lok..
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017