本文介绍了排序gridview时无法找到列。 E.sortexpression与列名匹配,但仍然显示无法找到列的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 受保护的Sub SortRecords(发送者为对象,e为GridViewSortEventArgs) Dim dt As New DataTable(GridView1.DataSource) Dim SortDir As String = String.Empty Dim sortExpression As String = e.SortExpression Dim sortedView As DataView = dt.DefaultView 如果sortedView IsNot Nothing那么 如果direction = SortDirection.Ascending那么 direction = SortDirection.Descending SortDir =Desc 否则 方向= SortDirection.Ascending SortDir =Asc 结束如果 sortedView.Sort = e.SortExpression& &此行上出现SortDir'错误 GridView1.DataSource = sortedView GridView1.AllowSorting()= True GridView1.DataBind() 结束如果 结束子 公共物业方向为SortDirection 获取 如果ViewState(方向 )什么都没有 ViewState(direction)= SortDirection.Ascending 结束如果 返回DirectCast(ViewState(direction) ,SortDirection) 结束获取 设置(ByVal值为SortDirection) ViewState(direction)= Value 结束套件 结束物业 我尝试过: 我尝试过使用其他方法,但问题仍然存在Protected Sub SortRecords(sender As Object, e As GridViewSortEventArgs) Dim dt As New DataTable(GridView1.DataSource) Dim SortDir As String = String.Empty Dim sortExpression As String = e.SortExpression Dim sortedView As DataView = dt.DefaultView If sortedView IsNot Nothing Then If direction = SortDirection.Ascending Then direction = SortDirection.Descending SortDir = "Desc" Else direction = SortDirection.Ascending SortDir = "Asc" End If sortedView.Sort = e.SortExpression & " " & SortDir 'error occur on this line GridView1.DataSource = sortedView GridView1.AllowSorting() = True GridView1.DataBind() End IfEnd Sub Public Property direction As SortDirection Get If ViewState("direction") Is Nothing Then ViewState("direction") = SortDirection.Ascending End If Return DirectCast(ViewState("direction"), SortDirection) End Get Set(ByVal Value As SortDirection) ViewState("direction") = Value End Set End PropertyWhat I have tried:I've tried using other method but the problem still occur推荐答案 St使用调试器的艺术:在发生错误的行上放置一个断点,并查看 e.SortExpression 和 SortDir 。 然后仔细查看 dt 中的哪些列 - 我们不能为您做任何事情:我们无法访问您的数据! 如果由于未在开发计算机上运行而无法使用调试器,请将值记录到文件中,然后检查文件发生错误后。 猜测,问题出现在代码的其他地方 - 也许Gridview DataSource尚未设置 - 但没有明确的信息我们甚至在黑暗中比你更多! :laugh:Start with the debugger: put a breakpoint on the line where the error occurs, and look at exactly what is in both e.SortExpression and SortDir.Then look at exactly what columns are in your dt - we can't do any of that for you: we don't have access to your data!If you can't use the debugger for this because it isn't running on your development machine, then log the values to a file, and examine the file after the error occurs.At a guess, the problem is elsewhere in your code - perhaps the Gridview DataSource isn't set yet - but without clear information we are even more in the dark than you are! :laugh:当你尝试在sort表达式中设置排序方向时,我认为你错了。您应该使用GridViewSortEventArgs的SortDirection属性: 替换I think you are wrong when you try to setup the sort direction in the the sort expression itself. You should use the SortDirection property of the GridViewSortEventArgs instead:ReplacesortedView.Sort = e.SortExpression & " " & SortDir withwithe.SortDirection = direction 你也可以摆脱你的SortDir变量。You can also get rid of your SortDir variable. 这篇关于排序gridview时无法找到列。 E.sortexpression与列名匹配,但仍然显示无法找到列的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-27 12:30
查看更多