Delete all rows on pageload

6 posts, 0 answers
  1. rinu
    rinu avatar
    15 posts
    Member since:
    Jun 2010

    Posted 18 Nov 2015 Link to this post

    Hi all,

     How do i delete all rows on pageload event ?

    Regards

    Roma

  2. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 20 Nov 2015 Link to this post

    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
  3. rinu
    rinu avatar
    15 posts
    Member since:
    Jun 2010

    Posted 22 Nov 2015 in reply to Pavlina Link to this post

    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" . 

     

  4. rinu
    rinu avatar
    15 posts
    Member since:
    Jun 2010

    Posted 22 Nov 2015 in reply to rinu Link to this post

    I am even open to loop through the radGrid and delete the records. can you show me some code to do that ?
  5. Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 24 Nov 2015 Link to this post

    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
  6. rinu
    rinu avatar
    15 posts
    Member since:
    Jun 2010

    Posted 26 Nov 2015 Link to this post

    Thanks Pavlina , That solved my problem
Back to Top