views:

649

answers:

2

I am using the ADO.NET Entity Framework data model. I send data from SQL to a GridView via ADO.NET Entity Framework.

But how can i sort gridview'columns click if i use EF

+1  A: 

Read this for sorting an ASP.NET GridView object MSDN... :)

Chalkey
+1  A: 

Are you using an EntityDataSource ? Have you enabled the AllowSorting and AllowPaging properties on the GridView ?

    <asp:GridView ID="GridView1" runat="server" 
        AllowPaging="True" AllowSorting="True" 
        AutoGenerateColumns="True" 
        DataSourceID="EntityDataSource1">
    </asp:GridView>
    <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
        ConnectionString="......" 
        EntitySetName="......." 
        Select=".........." OrderBy="......">
    </asp:EntityDataSource>

Marc

marc_s
i dont use EntityDataSource why i need it. I want to make it C# codes.
Phsika
USE IT ! that's the way to get sorting and paging for free.
marc_s
How to sort gridview columns by Clicking columns? i dont use below
Phsika
void LoadProducts() { ABCBusinessFrameWork._SQLAccessLayer client = new ABCBusinessFrameWork.LoadData(); Session["TaskTable"] = client.GetAllData("sp_GetAllProducts", CommandType.StoredProcedure); gvProducts.DataSource = Session["TaskTable"]; gvProducts.DataBind(); }
Phsika
protected void gvProducts_Sorting(object sender, GridViewSortEventArgs e) { //Retrieve the table from the session object. DataTable dt = Session["TaskTable"] as DataTable;
Phsika
My advice: forget about doing this manually - USE the EntityDataSource! You'll save yourself a LOT of grief and code!!
marc_s