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

Clearing Grid ItemsCollection

7 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 13 Apr 2011, 08:02 PM

I have a grid that I bind in a NeedDatasource and I need to clear the items in the grid from outside the NeedDataSource.

I've tried the below, and grid.items.count doesn't change.

Me.rgProductModelSizeSubmittalDrawing.DataSource = Nothing
Me.rgProductModelSizeSubmittalDrawing.DataBind()

As mentioned by many other posts that I've read, a .clear would be really nice.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Apr 2011, 07:59 AM
Hello Roger,

Try the following line code snippet to clear the RadGrid.

Vb.Net:
Me.rgProductModelSizeSubmittalDrawing.DataSource = New String() {}
Me.rgProductModelSizeSubmittalDrawing.Rebind()

-Shinu.
0
Roger
Top achievements
Rank 1
answered on 18 Apr 2011, 05:56 PM
I've already tried that, it didnt' work either.

Thanks for the suggestion
0
Mira
Telerik team
answered on 21 Apr 2011, 12:10 PM
Hello Roger,

The NeedDataSource event is fired when a call to the grid's Rebind method takes place. If you want to clear the datasource of the grid based on some condition, this should happen in the NeedDataSource event handler:
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
    If 'some condition
        RadGrid1.DataSource = New String() {}
    End If
End Sub

I hope this helps.

All the best,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jis
Top achievements
Rank 1
answered on 10 May 2014, 11:34 AM
Is it possible in client side.I mean binding a grid with nothing  in client side.
0
Jis
Top achievements
Rank 1
answered on 10 May 2014, 11:35 AM
Is it possible in client side.I mean binding a grid with nothing  in client side.
0
Princy
Top achievements
Rank 2
answered on 12 May 2014, 06:31 AM
Hi Jis,

You can try the following code snippet to empty your radgrid.

JS:
var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
masterTable.set_dataSource([]);
masterTable.dataBind();

Thanks,
Princy
0
Jis
Top achievements
Rank 1
answered on 12 May 2014, 07:04 AM
Thanks Princy..That working fine.
Tags
Grid
Asked by
Roger
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Roger
Top achievements
Rank 1
Mira
Telerik team
Jis
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or