开发者

Getting the IListSource does not contain any data sources exception in ASP.NET

I am trying to bind ListView control to data contained in a DataSet type. I have also introduced paging through DataPager type.

On the first call to DataBind, the binding happens perfectly. But, when i click Next to retrieve the next set of results, even though my function returns the appropriate DataSet, it is unable to do binding.

 void getSubSet(int rowindex, DataSet resultSet, int pageSize)
 {
   DataSet ds = new DataSet();
   DataTable tb = new DataTable();
   for (int cols = 0; cols < resultSet.Tables[0开发者_运维技巧].Columns.Count; cols++)
   {
     DataColumn dc = new DataColumn(resultSet.Tables[0].Columns[cols].ColumnName,
                                           resultSet.Tables[0].Columns[cols].DataType);
     tb.Columns.Add(dc);
   }
   for (int i = rowindex; ((i < resultSet.Tables[0].Rows.Count) && (i < rowindex + pageSize)); i++ )
   {
     DataRow rowToBeAdded = resultSet.Tables[0].Rows[i];
     DataRow newRow;
     newRow = tb.NewRow();
     for (int j = 0; j < resultSet.Tables[0].Columns.Count; j++)
          newRow[j] = rowToBeAdded[j];
     tb.Rows.Add(newRow);
   }
   ds.Tables.Add(tb);
   return ds;
 }

DataSet resultSet contains all results.

The above snippet returns perfect results, but upon

LV.DataSource = getSubSet(newIndex, resultSet, pageSize);
LV.DataBind();

where LV is a ListView control in the .aspx page. On second call during paging returns exception.

Please help! Thanks!


Are you sure that the rsesultSet parameter passed to the getSubSet method is not empty the second time the method gets executed (on paging)? Debug the code to see whether the returned ds contains data.

If you want to simplify and reduce your code, use SqlDataSource (instead of binding by hand) and assign it directly to the LV via DataSourceID.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜