3

So what does this exactly means?

Some advised that to circumvent around this error, only bind a gridview to a dataset when the rows count of the datatable is greater than zero.

but how about if for example your search yielded no record returned, so your datatable would have no rows, but still, you can still bind to the dataset?

Aside from checking if rows are in the dataset (or datatable), how would I ensure that the ilist contains valid datasource?

what's the best method for this?

Batuta
  • 1,684
  • 17
  • 48
  • 62

6 Answers6

7

Make sure you use this:

if (!this.IsPostBack)
{
}

Also you can check the dataSet.Tables.Count > 0 then return dataSet else return null;

I think the DataSet return have Count = 0

DreamTeK
  • 32,537
  • 27
  • 112
  • 171
DevMania
  • 2,311
  • 4
  • 25
  • 43
1

Please check your connection string. In my case, the connection string was the problem.

Gautam Jain
  • 6,789
  • 10
  • 48
  • 67
1

Old thread, but just wanted to let people know that I got this error recently (while looking at our legacy system) and turns out the issue was related to binding a datasource directly to a dataset.

Dim MyDs As new Dataset
MyDs = GetFromDataBase()

MyDropDownList.Datasource = MyDs

The strange thing was that I have done code like this for years and years, plus it worked fine on my local machine (best Dev line ever =P) But on the server it just kept crashing out.

I had to do

MyDropDownList.Datasource = MyDs.Tables(0)

Maybe this is something to do with .Net 4.0 on Windows 2008 Server, not sure, but hopefully this might help someone wasting 30mins of bug hunting for something that your eyes say is perfectly fine (allbeit legacy) code.

Bevan
  • 11
  • 1
  • I was in precisely the same situation. Found it strange that the app was working perfectly fine in IIS on my local machine. Change the line as follows: `gridView.DataSource = dataSet.Tables[0];` and presto – Carel Feb 11 '16 at 08:31
0

The IListSource does not contain any data sources.

Why is this error occur when the web site is hosted in IIS server.

Is this Because of the Data source not connecting properly with the server.

I'm using this postback check while calling the method.

if (!this.IsPostBack) { ... }
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
0

make sure that you closed the connection after binding data to the gridview

-1

In my case, my page was supposed to redirect to another page, but that URL didn't exist. So I got this error. Please check the URL if you are redirecting to some other page.