必须在使用dataview之前设置错误'datatable。 '真的不明白这个错误..你能解释一下吗?smh帮助解决问题?提前致谢 [英] Error' datatable must be set prior to using dataview. 'Dont really understand this error..can you explain it to me and smh help solve the problem? Thanks in advance
本文介绍了必须在使用dataview之前设置错误'datatable。 '真的不明白这个错误..你能解释一下吗?smh帮助解决问题?提前致谢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
受保护的 Sub SortRecords(sender 作为 对象,e 作为 GridViewSortEventArgs)
Dim dv 作为 新 DataView(GridView1.DataSource)
Dim SortDir As String = 字符串 .Empty
Dim sortExpression 正如 字符串 = e.SortExpression
如果 dv < span class =code-keyword> IsNot Nothing 然后
如果方向= SortDirection.Ascending 那么
direction = SortDirection.Descending
SortDir = Desc
ViewState( < span class =code-string> SortExpression)= Convert.ToString(e.SortExpression& & SortDir)
Else
direction = SortDirection.Ascending
SortDir = Asc
ViewState( SortExpression)= Convert.ToString(e.SortExpression& & ; SortDir)
结束 如果
< span class =code-keyword>结束 如果
' BindGridView()
dv.Sort = ViewState( SortExpression)。ToString ' 错误发生在这里
' 必须在使用DataView之前设置DataTable
GridView1.DataSource = dv
GridView1.AllowSorting = True
GridView1.DataBind()
结束 Sub
我的尝试:
我尝试将数据绑定到数据表而不是数据视图,但仍然会发生相同的错误。
解决方案
我认为你做错了。请参阅 - GridView.Sorting事件(System.Web.UI.WebControls ) [ ^ ]。
Protected Sub SortRecords(sender As Object, e As GridViewSortEventArgs)
Dim dv As New DataView(GridView1.DataSource)
Dim SortDir As String = String.Empty
Dim sortExpression As String = e.SortExpression
If dv IsNot Nothing Then
If direction = SortDirection.Ascending Then
direction = SortDirection.Descending
SortDir = "Desc"
ViewState("SortExpression") = Convert.ToString(e.SortExpression & " " & SortDir)
Else
direction = SortDirection.Ascending
SortDir = "Asc"
ViewState("SortExpression") = Convert.ToString(e.SortExpression & " " & SortDir)
End If
End If
'BindGridView()
dv.Sort = ViewState("SortExpression").ToString 'error happen here
'DataTable must be set prior to using DataView
GridView1.DataSource = dv
GridView1.AllowSorting = True
GridView1.DataBind()
End Sub
What I have tried:
I've tried bound the data to datatable instead of the dataview at first but same error still happen.
解决方案
I think you are doing it wrong. Refer - GridView.Sorting Event (System.Web.UI.WebControls)[^].
这篇关于必须在使用dataview之前设置错误'datatable。 '真的不明白这个错误..你能解释一下吗?smh帮助解决问题?提前致谢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文