How to Clear RadGrid??

17 posts, 0 answers
  1. joni
    joni avatar
    23 posts
    Member since:
    Apr 2008

    Posted 21 May 2008 Link to this post

    Hi,
    This seems like it should be so simple - but I can't get it to work. I have a RadGrid , using AjaxManager and NeedDataSource.  I execute different queries - depending on the search criteria selected and return a dataset that is set to the DataSource:

    this.RadGrid1.MasterTableView.DataSource = ds;

    this.RadGrid1.MasterTableView.DataMember = ds.Tables[0].ToString();


    This works great - however I have a clear button that I am trying to clear the grid with - the code is executed but the rows still are in the grid on the screen  - I set the DataSource and DataMember to null and rebind.

    protected

    void btnClear_Click(object sender, EventArgs e)

    {

    this.RadGrid1.MasterTableView.DataSource = null;

    this.RadGrid1.MasterTableView.DataMember = null;

    this.RadGrid1.DataSource = null;

    this.RadGrid1.Rebind();

    }

    So when that didn't work I thought I would manually try to remove the rows and I can't seem to find any RowsCollecion to iterate through and remove.

    What am I missing here?? Any help is appreciated. Thanks!

    Edited to add - I have EnableViewState set to True on the grid

    Edited again - I was able to get the functionality I wanted by creating an empty table and setting the dataset to the datasource and the empty table to the datamember and then doing the this.RadGrid1.Rebind(); 

    I would still be curious as to why setting the datasource and datamember to null would not work. It seems as though this functionality works when the NeedDataSource event is called automatically without having to do a Rebind.

    joni

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 May 2008 Link to this post

    Hi Joni,

    Try the following line code snippet to clear the RadGrid.

    CS:
     protected void Button1_Click(object sender, EventArgs e)  
        {  
            RadGrid1.DataSource = new string[] { };  
        } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. joni
    joni avatar
    23 posts
    Member since:
    Apr 2008

    Posted 22 May 2008 Link to this post

    Hi Princy,
    Thanks for the response. That seems to work well if you don't go over your page limit. If you do and you have paging enabled it leaves the Change Page and Page Numbers and the message regarding how many items of how many items are being displayed on the page status bar.  Any ideas how to clear this information? Thanks!!

    Edited to add: I installed the latest hotfix and this issue has been fixed - thanks!!

    joni
  5. Jason
    Jason avatar
    9 posts
    Member since:
    Oct 2010

    Posted 09 Jan 2011 Link to this post

    RadGrid1.DataSource = new string[] { }; 
    does not work even if you also do RadGrid1.DataBind();
    Need a way to clear the grid...rows are getting duplicated.


    .
    Please explain how I can display a RadGrid after making changes
    to the datasource and not get duplicated rows. What is happening is...
    RadGrid1.DataSource = null; <--does nothing
    RadGrid1.DataBind(); <--does nothing...item collection still has items











    RadGrid1.DataSource = List<of myObjects> <--is appended to the current RadGrid1.DataSource





  6. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 13 Jan 2011 Link to this post

    Hello Christopher,

    You won't get duplicated rows under normal circumstances. Are you changing the grid structure dynamically on postback?
    If this is not the case, could you please let me know how to reproduce the problem on my end?

    Best regards,
    Daniel
    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.
  7. Anjan Nimmana
    Anjan Nimmana avatar
    5 posts
    Member since:
    Oct 2009

    Posted 16 Mar 2011 Link to this post

    I am facing problem with duplicate records in Radgrid after postback.

    I tried with below statement to clear the radgrid. but it is not working.
    RadGrid1.DataSource = new string[] { };

    I also tried with below statement to clear the radgrid. I put this statement in button click before redirecting to next page. but it is also not working. 
    RadGrid1.Dispose();

    Can you please suggest, how to clear or remove data in Radgrid while moving to next page.
  8. Karl
    Karl avatar
    172 posts
    Member since:
    Sep 2010

    Posted 12 Apr 2011 Link to this post

    Try the following, it works for us.

    RadGrid1.DataSource = null;
    RadGrid1.DataBind();

    It should be noted though that if your cycling through pages of the grids data, you shouldn't need to clear the data source so you may need to look into how you're binding your data if this is what you mean when you said...

    "Can you please suggest, how to clear or remove data in Radgrid while moving to next page."
  9. Dnyaneshwar
    Dnyaneshwar avatar
    2 posts
    Member since:
    Sep 2014

    Posted 02 Sep 2014 in reply to Karl Link to this post

    You can clear grid and show empty message by using following code.
     RadGrid1.DataSource = new string[] { };
                RadGrid1.DataBind();
  10. Dnyaneshwar
    Dnyaneshwar avatar
    2 posts
    Member since:
    Sep 2014

    Posted 02 Sep 2014 in reply to Karl Link to this post

     RadGrid1.DataSource = new string[] { };
                RadGrid1.DataBind();
  11. Gowtham
    Gowtham avatar
    7 posts
    Member since:
    Jun 2013

    Posted 22 Jan 2015 in reply to Princy Link to this post

    Working fine... thanks Princy
  12. Robert
    Robert avatar
    3 posts
    Member since:
    Apr 2016

    Posted 22 Jul Link to this post

    Using RadGrid1.DataSource = new string[] { };

     

    does not working in the NeedDataSource event.

  13. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 27 Jul Link to this post

    Hi Robert,

    When you set the DataSource for the RadGrid to an empty array there would be no records displayed in the grid.

    Would you elaborate in more detail on what is not working as expected on your end? What is the behavior that you would like to implement?


    Regards,
    Viktor Tachev
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  14. Robert
    Robert avatar
    3 posts
    Member since:
    Apr 2016

    Posted 27 Jul in reply to Viktor Tachev Link to this post

    If I use the line RadGrid1.DataSource = new string[] { }; in the NeedDataSource event, I still see the empty rows that were displayed previously.

    I have to use RadGrid1.DataSource = null and cross my fingers.

  15. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 29 Jul Link to this post

    Hello Robert,

    Would you open a support ticket and send a runnable sample where the behavior you are seeing is replicated? This will give us better understanding of your scenario. Moreover, we will be able to examine the behavior and give more to-the-point suggestions on how to achieve your goal.

    Regards,
    Viktor Tachev
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  16. ed mihaly
    ed mihaly avatar
    11 posts
    Member since:
    May 2010

    Posted 06 Sep Link to this post

    Hi,

    radGridView1.Columns.Clear();
    radGridView1.Rows.Clear();

    E,

     

  17. Jonathan
    Jonathan avatar
    5 posts
    Member since:
    Sep 2016

    Posted 17 Oct in reply to Dnyaneshwar Link to this post

    This does not work in ASPX.VB you encounter an error "Overload Resolution failed because no accesible new accepts this number of arguments "
  18. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 18 Oct Link to this post

    Hello Jonathan,

    Have you tried supplying an empty array to RadGrid as suggested by Viktor?

    Regards,
    Daniel
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017