动态绑定datagrid,点击列头进行排序显示一片空白,大家帮帮忙啊!!!!!!!!!!!

mistletoe_kong 2009-01-13 11:01:34
绑定datagrid的代码

col = New BoundColumn
col.DataField = "order_date"
col.HeaderText = "订货日期"
col.SortExpression = "order_date"
col.ItemStyle.HorizontalAlign = HorizontalAlign.Right
DataGrid1.Columns.Add(col)


排序代码
Private Sub MySort()
Dim thisSortField, thisMode As String
Dim conn As New SqlClient.SqlConnection(sysConfig.ConStr)
Dim myDataAdapter As New SqlClient.SqlDataAdapter
thisSortField = Me.DataGrid1.Attributes("SortExpression")
thisMode = Me.DataGrid1.Attributes("SortDirection")

Dim dv As New DataView
Dim ds As New DataSet
strsql="select * from 表"
myDataAdapter = New SqlClient.SqlDataAdapter(strsql, conn)
myDataAdapter.Fill(ds)
dv = ds.Tables(0).DefaultView
dv.Sort = thisSortField + " " + thisMode
Me.DataGrid1.DataSource = dv
Me.DataGrid1.DataBind()
End Sub

DataGrid1_SortCommand事件的代码

Dim SortField As String
SortField = e.SortExpression.ToString

Me.DataGrid1.Attributes("SortExpression") = SortField
If Me.DataGrid1.Attributes("SortDirection") = "ASC" Then
Me.DataGrid1.Attributes("SortDirection") = "DESC"
Else
Me.DataGrid1.Attributes("SortDirection") = "ASC"
End If

MySort()

我点击完列头根本就不触发DataGrid1_SortCommand事件,怎么回事呀???????????在线等

...全文
61 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
mistletoe_kong 2009-02-19
  • 打赏
  • 举报
回复
但是没有给出正确答案
a2krh 2009-01-19
  • 打赏
  • 举报
回复
有类似问题的回答的,可以先参考一下
http://topic.csdn.net/u/20070203/11/cf2b88c4-e248-45f0-ac49-e885221c1809.html

16,718

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧