Gridview Autosort Without allowing users to sort

Hello everyone here is the problem, and I hope you can help me

I use a Gridview in my asp.net page to show the data from my sql database.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
    <Columns>
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name"></asp:BoundField>
        <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email"></asp:BoundField>
        <asp:BoundField DataField="College" HeaderText="College" SortExpression="College"></asp:BoundField>
    </Columns>
</asp:GridView>

The gridview itself is working fine but i want to auto sort by College but I DONT want the users to be able to sort anything on click. Hope you can help thanks.

Upvotes: 0

Views: 1102

Answers (1)

शेखर
शेखर

Reputation: 17614

In your Data-Source SqlDataSource1 add order by College.

And change the bound filed

<asp:BoundField DataField="Name" HeaderText="Name">
......

Set property of gridview AllowSorting = false

Upvotes: 2

Related Questions