Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to cast object of type 'System.Data.DataView' to type 'System.D

Status
Not open for further replies.

stonehead

Technical User
May 2, 2007
58
US
Hi all,

I'm trying to do sorting for my gridview. This is the error I got
Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'

for this line
gvDetail.DataSource = SortDataTable(Session("myTable"), False)

Please help.



Protected Sub gridView_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)

GridViewSortExpression = e.SortExpression

Dim pageIndex As Integer = gvDetail.PageIndex


gvDetail.DataSource = SortDataTable(Session("myTable"), False)


gvDetail.DataBind()

gvDetail.PageIndex = pageIndex

End Sub
 
Since i can't see all of your code, I would try casting the session object to a datatable first.

Code:
SortDataTable(DirectCast(Session("myTable"),DataTable), False)
 
Thank you for your prompt response. I found out why I got the error. It's because I put
Session("myTable") = New Data.DataView()
before Page.IsPostBack
 
Glad you found it, but you should always cast your objects when you are pulling from the session object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top