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

Delete all rows on pageload

5 Answers 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rinu
Top achievements
Rank 1
rinu asked on 18 Nov 2015, 06:45 AM

Hi all,

 How do i delete all rows on pageload event ?

Regards

Roma

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 20 Nov 2015, 04:27 PM
Hi,

If you want to display empty grid on PageLoad you can refer to the forum thread below:
http://www.telerik.com/forums/empty-datasource-radgrid-problem

In case you are trying to achieve something else elaborate a bit more.

Regards,
Pavlina
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
rinu
Top achievements
Rank 1
answered on 22 Nov 2015, 01:36 PM

yes this is exactly what i am trying to do but i got the following error. 

"Both DataSource and DataSourceID are defined on 'RadGrid1'.  Remove one definition" . 

 

0
rinu
Top achievements
Rank 1
answered on 22 Nov 2015, 01:37 PM
I am even open to loop through the radGrid and delete the records. can you show me some code to do that ?
0
Pavlina
Telerik team
answered on 24 Nov 2015, 05:58 PM
Hello,

Regarding the error you received it is caused by the fact that the grid is not populated properly because you have set both DataSource and DataSourceID at the same time. For example if you have assigned your datasource for the grid through NeedDataSource event setting DataSource to empty string on PageLoad should work and the code will looks like the one below:
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           RadGrid1.DataSource = String.Empty;
       }
         
   }
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
   {
       RadGrid1.DataSource = GetDataTable();
   }
 
Additionally, if you want to loop through grid items and delete specific one you need to handle grid PreRender event because pageLoad is too early in the lifecycle and the grid is not populated yet.

Regards,
Pavlina
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
rinu
Top achievements
Rank 1
answered on 26 Nov 2015, 07:05 AM
Thanks Pavlina , That solved my problem
Tags
Grid
Asked by
rinu
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
rinu
Top achievements
Rank 1
Share this question
or