This blog is about the dotnet.all types of codes,news about dotnet including asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.ncluding asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.asp.net programming,dot net programming,dotnet programs,dotnet source code,source code.

Free Hosting

Free Hosting

Showing posts with label sorting to a datagrid. Show all posts
Showing posts with label sorting to a datagrid. Show all posts

Sunday, November 2, 2008

asp.net code To add sorting to a datagrid

This is the code that goes in the html of the datagrid

PageSize="50">




/////////code behind

Private Sub dgView_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgView.SortCommand
Dim arrSort(1) As String

arrSort = txtSort.Value.Split(" "c)

'' If the selected item to sort by equals the previous item sorted then ...
If e.SortExpression = arrSort(0) Then
'' if the current sort type equals ASC then set sort type equal to DESC
If arrSort(1) = "ASC" Then
txtSort.Value = e.SortExpression & " DESC"
Else
txtSort.Value = e.SortExpression & " ASC"
End If
Else
txtSort.Value = e.SortExpression & " ASC"
End If

'' Bind the newly sorted data to the DataGrid
dgView.EditItemIndex = -1
Call bindData()
End Sub


Private Sub bindData()

Dim dt As New DataTable
dt = getfromdatabase()

Dim dv As DataView = New DataView(dt)
dv.Sort = txtSort.Value

dgView.DataSource = dv
dgView.DataBind()


If Not dt Is Nothing Then dt.Dispose()
dt = Nothing
End Sub


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Me.IsPostBack Then
txtSort.Value = "ID ASC"
bindData()
End If
End Sub

dotnet(.Net) Project Source code Downloads and Tutorials

Email Subscrption



Enter your email address:

Delivered by FeedBurner

Feedburner Count

Unique Visitor

Design by araba-cı | MoneyGenerator Blogger Template by GosuBlogger