Link to home
Start Free TrialLog in
Avatar of whiwex
whiwex

asked on

How to create a sortable gridview at design time

Does anyone have  example vb code that will take a datable and bind it to a sortable gridview.
I'm using VB and I query a access database and create datatable  from this datatable I create another datatable and bind this datatable to the gridview. I want to be able to sort the gridview but it doesn't sort.
Thanks
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Something like this example (SQL Server):
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT Select * From UserProfile Where UserId=@UserId">
                <SelectParameters>
                    <asp:QueryStringParameter Name="userid" DefaultValue="-1" />
                </SelectParameters>
            </asp:SqlDataSource>
            <asp:GridView ID="GridView1" runat="server" AllowSorting="true" DataSourceID="SqlDataSource1">
                <Columns>
                    <asp:BoundField DataField="Name" SortExpression="Name" />
                    <asp:BoundField DataField="Address" SortExpression="Address" />
                    <asp:BoundField DataField="City" SortExpression="City" />
                    <asp:BoundField DataField="State" SortExpression="State" />
                </Columns>
            </asp:GridView>

Open in new window

Avatar of whiwex
whiwex

ASKER

I'm looking for this in VB
That is just the HTML, and isn't language specific.  It is only a portion of the HTML that you are going to need.  Create a new web page, and within the <form> elements, paste that HTML.  Then, you can configure an SqlDataSource to connect to your database.

Bob
Avatar of whiwex

ASKER

I don't know the asp side so that's why I'm trying to do this backside i.e. at the server
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of whiwex

ASKER

See here's my poblem
I have a gridview called gridview1
I query a vendors database and get a list of all vendors and create a datatabe called dtVendors.
Then for each vendor in the dtVendors datatable I query a history database and get all the sales by the vendor.
Then sum the total of the vendors sales  and put the Vendors name and total sales in a history datatable called dtHistory.
The dtHistory datatable is binded to the gridview1. This all works fine. What i want to be able to do is allow the user to click on either the total sales or the vendors name and have the gridview sort.
So how do I setup the accessdatasource?
You don't need to set up the AccessDataSource.  The GridView will handle all that for you.

Bob
Avatar of whiwex

ASKER

Problem is when I click the header it doesn't sort.
AllowSorting = True?

Bob
Avatar of whiwex

ASKER

Yes I've tried that
Can you show me what it is doing incorrectly (attach a snapshot .png file)?

Bob