473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 5258
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 that the grid is sorted on that column. When I...
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 expression for each field as the anme of that...
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 ======= Development information about the page is as follows 1....
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 the layout of the grid (add/remove columns). I...
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 columns is a DataGridViewComboBoxColumn, doing what...
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 rebind my datatable to reflect the changes in...
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 column called status. The user sorts on status and it...
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. Now I want to add sorting to it. So I create...
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 grid view. Autogenerate columns is off, and I...
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 I can't get the sorting to work so I wrote some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.