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

Loop through Filtered Data - Grid

12 Answers 761 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jako
Top achievements
Rank 1
Jako asked on 24 Oct 2012, 12:26 PM
Hi there

I have a RadGrid that a user can apply filters to. Once they click on a submit button, I want to extract all filtered rows and then process the data from there.

Is there a built in function to only retrieve the filtered data?

Thank you.

12 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 24 Oct 2012, 01:28 PM
Hello Jako,

Once you apply a data operation to RadGridView (filtering, grouping, sorting) the resulted view is stored in the ChildRows collection of the template. So you can access your rows from there.

More information regarding this matter is available here: http://www.telerik.com/help/winforms/gridview-rows-rows-vs-childrows.html.
 
Greetings,
Stefan
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Jako
Top achievements
Rank 1
answered on 24 Oct 2012, 01:31 PM
Thanks Stefan, that is great!
0
Jako
Top achievements
Rank 1
answered on 29 Oct 2012, 11:48 AM
Hi Stefan

This seems to be for WinForms, I am using a web application with the AJAX controls.

I can't seem to find how to implement the ChildRows using a RadGrid? I doesn't have any NestedViews, I just want to get the filtered rows from a RadGrid

Thanks
0
Jako
Top achievements
Rank 1
answered on 29 Oct 2012, 12:32 PM
I have done a little hack as I couldn't find any way to just plainly get the filtered result. The itemCount is just to validate that its working.

protected void uxSendMail_Click(object sender, EventArgs e)
{
    int itemCount = 0;
 
    uxSitesGrid.AllowPaging = false;
    uxSitesGrid.Rebind();
 
    foreach (GridDataItem gridRow  in uxSitesGrid.Items)
    {
        itemCount += 1;
    }
 
    System.Windows.Forms.MessageBox.Show(itemCount.ToString());
 
    uxSitesGrid.AllowPaging = true;
    uxSitesGrid.Rebind();
}
0
Jako
Top achievements
Rank 1
answered on 29 Oct 2012, 12:53 PM
Just another thing, when you have a checkbox as one of your columns, it loses its status when you page?

Is there a way to keep the status accros paging?
0
Eyup
Telerik team
answered on 31 Oct 2012, 08:02 AM
Hi Jako,

Please note that RadGrid does not preserve the selected items or the state of Template controls upon performing database operations. Therefore, although you will get the selected items successfully on any other server event, their state will reset when you fire a command regarding a datasource request.

You could save the selected items in a collection variable and use it when necessary:
http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-client-sorting-paging-grouping-filtering.html
or
http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-on-sorting.html

I hope this will prove helpful.

Kind regards,
Eyup
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.
0
Jako
Top achievements
Rank 1
answered on 31 Oct 2012, 11:34 AM
Hi Eyup

Thanks for the response. What I ended up doing was to handle the checkbox change event and then add/remove the DataKey to a List<string> and then at the end remove those from my filtered grid.

Bit of a work around, but working 100% now.

Thank you.
0
Clara
Top achievements
Rank 1
answered on 05 Nov 2018, 12:18 PM

Hello,

I have an issue in regards to the topic specified above.

I have a radgrid in a winform where data is populated for the user. Then, when the data is populated, Users have to apply some filters ,depend on the request, and submit  process via clicking a button on the screen.

The problem is that I want to get the current data on the grid (after applying the filters) but I keep struggleing with that. Please it is quite urgent. Can you help me? Let me show you the two options that I am doing (none of them are working for me)

1st Option

System.Data.DataTable dt_filtered = new DataTable();

string filterexpression = string.Empty;

filterexpression = radGridView1.MasterTemplate.FilterDescriptors[0].Expression;

dt_filtered = dtGrid.AsEnumerable().AsQueryable().Where(filterexpression).CopyToDataTable();

This option is giving me an error "LinqDataSource, Repeaters and "Expression Expected" exception".

 

The second option was to use this.radGridView1.ChildRows but since this is returning a RowInfo, we do not know how to add those rows into a datatable.

 

Pleasee heelp :(

 

Thanks so much in advance!

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Nov 2018, 08:38 AM
Hello, Clara, 
  
Note that RadGridView exposes two collections that contain data rows:
- Rows - contains all data rows that belong to RadGridView. Data operations such as grouping, sorting, filtering, etc. do not change the content of the collection or the order in which the row objects exist in the collection.
- ChildRows - returns the data rows that are currently represented by RadGridView in the order in which they appear. The collection is modified every time a data operation (grouping, sorting, filtering) occurs. 

You can iterate the ChildRows collection where each data row has a DataBoundItem property storing the source record of the associated collection as DataSource. Thus, you can fill a DataTable with the filtered data. 
 
Off topic, note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
n/a
Top achievements
Rank 1
answered on 25 May 2020, 09:52 AM

"Child Rows" does not work if filtered data spans across multiple pages.

It accounts records only from current page.

Any solution for looping through all filtered records (including all pages)?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 May 2020, 11:22 AM

Hi, Betsy,

Please refer to the following KB article which I believe would be suitable for your scenario: https://docs.telerik.com/devtools/winforms/knowledge-base/get-all-filtered-rows-in-gridview-with-paging 

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
n/a
Top achievements
Rank 1
answered on 28 May 2020, 08:50 AM

Thanks Dess

It worked perfectly as required.

Tags
GridView
Asked by
Jako
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Jako
Top achievements
Rank 1
Eyup
Telerik team
Clara
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
n/a
Top achievements
Rank 1
Share this question
or