asp.net click DataGrid column Header sort (vb.net)

Source: Internet
Author: User
asp.net|datagrid| sorting please follow the steps:
Properties of 1:datagrid
Allowsorting= ' true ': Enable DataGrid sorting
2: Inside the HTML (added to the table) add a <input id= "SortField" type= "hidden" value= "activity_student_id" "Name=" SortField "runat=" Server >
Change fields as Sort by
Sort expression and Word fields in 3:datagrid consistent


4: Add namespace Imports System.Data
Imports System.Data.SqlClient

5:if InStr (SortField. Value, "desc") = 0 Then
SortField. Value = e.sortexpression & "desc"
Else
SortField. Value = e.sortexpression & "ASC"
End If
Bindgrid ()
Description: "1" e.sortexpression equals the name of the field named "Sorted link being pressed".
"2" If InStr (SortField. Value, "desc") = 0 if the original sort method was sorted by "ascending sort." The Sort method (Softfield.value) is then set to "Desc" (for descending sorting). Otherwise set to "", expressed as "ascending sort"
"3" At this time Softfield.value obtained is "field" + "sort" then Bindgrid ().
Sub Bindgrid ()
txtSQL = "SELECT * from .... ... where ...?..
Dbset = ExecuteSQL (txtsql, errormsg) ' The way every programmer gets a dataset is different,
' Anyway, you'll find a way to get a dataset dataset, you can also refer to my VB Connection sqlserver2000 database function
Dim dtable as DataTable = dbset.tables (0)
Dim Dview as New DataView (dtable)
Dg. Sort = SortField. Value
Dg. DataSource = Dview
Dg. DataBind ()
End Sub





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.