GridView是2.0才有的新玩意,是MS推出來取代DataGrid的,
配合新的DataSource,要寫的CODE更少了,
以下是我在使用DataSource、GridView上遇到的問題
作法一:

如果GridView的DataSource是在程式中給gridview的,那排序跟換頁等程式都要自己撰寫,要在它的兩個事件中寫程式碼,我的做法是:
‘==========================
‘GridView 的換頁動作
‘==========================
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging

Me.GridView1.PageIndex = e.NewPageIndex
BindGridView()

End Sub

‘==========================
‘GridView 的排序動作
‘==========================
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
Dim strSort As String = ViewState(“sort”)

If Right(strSort, 4) = “desc” Then
ViewState(“sort”) = e.SortExpression
Else
ViewState(“sort”) = e.SortExpression + ” desc”
End If

BindGridView()

End Sub

作法二:

1. 還是拉一個SQLDataSource, 只連到資料庫, 並不做Select, update, insert, delete command的處理.
2. 並把Gridview的datasource只到這個SQLDataSource
3. 要異動Gridview的內容時, 將SQLDataSource.SelectCommand = SQL 指令, 重新做Gridview.DataBind()即可

相關參考:

http://phone.idv.tw/cs2/forums/thread/274.aspx