none
ASPNET GridView how to clear all results? RRS feed

  • Question

  • Dear All,

    I am using LinQ datasrouce with GridView.

    Due to the complexity of the query, the actual query is actually done in the LinqDataSource Selecting event.

    however, there are some cases where I wish to clear all the results and do not return any row in the Selecting event. May I know how can I do that?

    Example:

    protected void mDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
     if (NotValie)
     {
      // Here I wish to clear the e.Results so that the GridView do not show anything.
      return;
     }

     e.Result = from u in UserTbl
        select u;
    }

    Thanks in advance.

    Friday, March 26, 2010 3:20 AM

Answers

  • Example:

    protected void mDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
     if (NotValie)
     {
      // Here I wish to clear the e.Results so that the GridView do not show anything.
      return;
     }

     e.Result = from u in UserTbl
        select u;
    }

    You could use e.Cancel = true;

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by Chui Kean Friday, March 26, 2010 12:35 PM
    Friday, March 26, 2010 11:03 AM

All replies

  • Example:

    protected void mDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
     if (NotValie)
     {
      // Here I wish to clear the e.Results so that the GridView do not show anything.
      return;
     }

     e.Result = from u in UserTbl
        select u;
    }

    You could use e.Cancel = true;

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    • Marked as answer by Chui Kean Friday, March 26, 2010 12:35 PM
    Friday, March 26, 2010 11:03 AM
  • Roahn,

    Thank for the reply. I have made a mistake earlier and I thought your answer is not correct.

    Friday, March 26, 2010 12:06 PM
  • Hi,

    Thanks for your reply. If a reply is not an answer, please unmark it. Thanks a lot!


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Monday, March 29, 2010 11:12 AM