472,353 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

sorting in data grid run-time error: Cannot find table 0.

I am trying to implement the sort event in data grid. I set the data grid's
AllowSorting property = True. I implement the following code that should be
the event will fire when the user click any of the columns in the table:

Private Sub dgReport1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
dgReport1.SortCommand
Dim sortOrder As String = e.SortExpression.ToString()
Response.Write(sortOrder)
Dim ds As New DataSet
Dim dt As DataTable = ds.Tables(0)
dt.DefaultView.Sort = sortOrder
dgReport1.DataSource = ds.Tables(0).DefaultView
dgReport1.DataBind()
End Sub
When I click any of the columns in the table, it throw the following run
time error on line: Dim dt As DataTable = ds.Tables(0).

Run-time error
============
Cannot find table 0.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Cannot find table 0.
I have no idea why table 0 has problem. Because I am able to get the table
as folows:

Dim dt As DataTable = ds.Tables(0)
dgReport1.DataSource = dt
dgReport1.DataBind()

Please advise! Thanks !!

Nov 18 '05 #1
1 5185
Sure. But does the DataTable exist when you return to the form to sort it? I
doubt it. The DataTable is not persisted between invocations unless you
persist it. One approach is to save it to the Session state. When you return
on Postback, you'll need to rehydrate it.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Matthew Louden" <ma*******@hotmail.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
I am trying to implement the sort event in data grid. I set the data grid's AllowSorting property = True. I implement the following code that should be the event will fire when the user click any of the columns in the table:

Private Sub dgReport1_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
dgReport1.SortCommand
Dim sortOrder As String = e.SortExpression.ToString()
Response.Write(sortOrder)
Dim ds As New DataSet
Dim dt As DataTable = ds.Tables(0)
dt.DefaultView.Sort = sortOrder
dgReport1.DataSource = ds.Tables(0).DefaultView
dgReport1.DataBind()
End Sub
When I click any of the columns in the table, it throw the following run
time error on line: Dim dt As DataTable = ds.Tables(0).

Run-time error
============
Cannot find table 0.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Cannot find table 0.
I have no idea why table 0 has problem. Because I am able to get the table
as folows:

Dim dt As DataTable = ds.Tables(0)
dgReport1.DataSource = dt
dgReport1.DataBind()

Please advise! Thanks !!

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris H. | last post by:
Two Questions.... 1. On the DataGrid, if you click on the column titles it will sort the data on that column and put a little "arrow" to indicate...
12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort...
4
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress =======...
0
by: javatopia | last post by:
I am creating a data grid's columns on the fly in my web page. The Bind operation works just fine, and data is displayed correctly when I change...
0
by: Chris Botha | last post by:
Using VS2005, on the form is a DataGridView, a typed DataSet containing the data and a BindingSource between the grid and the dataset. One of the...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to...
0
by: DBC User | last post by:
I have a data grid. In it, it has 4 columns. I allow the user to sort the gird by column. I have around 1000 rows in my data grid. There is one...
4
by: kurt sune | last post by:
I have a an aspx page with a gridview. The gridview is data bound to a generic list of custom classes. The gridview's DataSource is thus not set....
5
by: Cindy Lee | last post by:
I'm getting my data from an XML file. The data binds fine, but I can't sort on it. Do I have to do anything special? I have enabled sorting on my...
1
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a grid view that pulls data from a dbf file. I set the Allow Sorting to true and I put my code in the Sorting event. The problem is that...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.