How To Programmatically Access the DataSet Created by a SQLDataSource

Posted on 2006-06-07
Last Modified: 2008-01-09
I noticed that when you use a SQLDataSource it will automatically do the sorting  on the GridView for you which is great.  I was  however unable to figure out a way to add an Filtering expression to the SQLDataSource's dataView so that I could filter the returned data without using a SQLDataAdapter ---> dataSet ---> dataView, etc.

Using the SQLDataAdapter solved the filtering problem but then I lost the automatic sorting on the GridView Columns provided by the SQLDataSource so now I'm basically, trying to combine two different methods to cut down on the code I have to write.

If I stick with the SQLDataAdapter I'll have to write code to figure out which column the user clicked on and wants to sort.  Any suggestions on ways to do this?

My preferred solution however is to programatically access the dataSet created by the SQLDataSource and simply filter on that and I would expect all of my problems will be solved.

Does anyone see a problem with this apporach and/or have suggestions on how to go about actually writing the code to accomplish this?

Thanks in Advance (TIA)
Question by:FoxProMari
    LVL 6

    Expert Comment

    First, I do not know how to access the dataset created by SqlDataSource.

    However, you should be able to have automatic sorting abilities in the gridview when using a FilterExpression on a SqlDataSource. (The DataSourceMode of the SqlDataSource must be DataSet)

    For example, if I have a GridView bound to SqlDataSource1, I can do this

    SqlDataSource1.FilterExpression = "CustomerId > 100";

    and the column sorting still works fine.

    Author Comment


    I found the answer here on the Experts-Exchange.

    I have dv declared globally and included the following line in the page_load !IsPostBack

                this.dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);

    I have another question that I'm getting ready to post concerning the best way to get my date values to order properly.  They don't sort correctly when I convert them from actual date values to char(8) values so that they display without the time.

    I'll ask the Administrator to close out this questions.  Thanks.
    LVL 5

    Accepted Solution

    Closed, 350 points refunded.
    Site Admin

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now