Avatar of ksfok
ksfok
 asked on

GridView Sorting with LING

Given the following HTML and codebehind:

 <form id="form1" runat="server">
    <div>
        <asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" BackColor="White"
            BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
            AllowSorting="true">
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            <Columns>
                <asp:BoundField DataField="Ename" HeaderText="Employee Name" SortExpression="Ename" />
                <asp:BoundField DataField="AnnSal" HeaderText="Annual Salary" DataFormatString="{0:c}"
                    SortExpression="AnnSal" />
            </Columns>
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <AlternatingRowStyle BackColor="#F7F7F7" />
        </asp:GridView>
    </div>
    </form>

   Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load

        If Not IsPostBack Then

            Dim query = From p In GetEmployeeList() Select p.Ename, AnnSal = (p.Sal * 12)

            Me.Gridview1.DataSource = query

            Me.Gridview1.DataBind()

        End If

    End Sub

The grid is populated OK but clicking on a field to sort generate this error:

The GridView 'Gridview1' fired event Sorting which wasn't handled.

How can event sorting handler be coded here?

Thanks for any help.

 
ASP.NET

Avatar of undefined
Last Comment
ksfok

8/22/2022 - Mon
Eladla

Eladla

ksfok

ASKER
How can your first example using datatable be used with my LING query?
How can my LING query be converted to datatable?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Eladla

The point is not the query itself, but what you do with the datagrid control
and that is unrelated to LINQ as far as I can tell.
Eladla

Eladla

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Eladla

Sorry, my mind just droped the fact you were using LINQ before :)
ksfok

ASKER
Please simply advise how to implement sorting with LING query. Thanks.
ASKER CERTIFIED SOLUTION
Eladla

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ksfok

ASKER
I have finally solved my problem in a different way, Thanks.
But what advantages does LING offer over a classic Sqldata source query? LINQ query seems to be much less flexible than a classic Sqldata source query. For example you can make a public function out of a classic Sqldata source query to pass back results, but not with LINQ query? What type would you use for a LINQ query result to make the function?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ksfok

ASKER
OK