I want the user to select the customer header and the data to then be sorted by customer name alphabetically.
I have added a sort expression to the data grid;
<asp:BoundField DataField="Customer"HeaderText="Customer" SortExpression="Customer"/>
However I get the following error:
The data source does not support sorting with IEnumerable data. Automatic sorting is only supported with DataView, DataTable, and dataSet.
I understand that the problem relates to BLL and DAL file however I am unsure how
to resolve the problem.
Does anyone know a simple solution to ressolve this problem?
Thank you for your help.
Satyapriya NayakPosted Mar 21, 2013, 6:33 AM
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Default.aspx.vb code
Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim sqlda As SqlDataAdapter
Dim com As SqlCommand
Dim ds As DataSet
Dim str As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
bindgrid("sname")
End If
End Sub
Sub bindgrid(ByVal s As String)
Try
con.Open()
str = "select * from student order by " & s
com = New SqlCommand(str, con)
Dim reader As SqlDataReader = com.ExecuteReader
DataGrid1.DataSource = reader
DataGrid1.DataBind()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Protected Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid1.SortCommand
bindgrid(e.SortExpression)
End Sub
End Class
Also refer
http://www.c-sharpcorner.com/uploadfile/9aea29/grid-view-paging-and-sorting-in-Asp-Net/default.aspx