The IListSource does not contain any data sources.

Posted by Kishore22 under ASP.NET on 9/20/2013 | Points: 10 | Views : 25880 | Status : [Member] | Replies : 4
how to bind the gridview

I am trying to add data in grid view



SqlDataAdapter da = new SqlDataAdapter("select * from tab", con);

System.Data.DataSet ds = new System.Data.DataSet();
GridView1.DataSource = ds;
GridView1.DataBind();




i am getting the below error please solvee
The IListSource does not contain any data sources.
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.Web.HttpException: The IListSource does not contain any data sources.

Source Error:


Line 30: System.Data.DataSet ds = new System.Data.DataSet();
Line 31: GridView1.DataSource = ds;
Line 32: GridView1.DataBind();
Line 33: }
Line 34:




Responses

Posted by: Allemahesh on: 9/20/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Kishore

Change you code as below:-

SqlDataAdapter da = new SqlDataAdapter("select * from tab", con); 

System.Data.DataSet ds = new System.Data.DataSet();
da.Fill(ds);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}


Happy Coding
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/20/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Kishore,

Have you solved the issue?

Happy Coding
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
You forgot to fill SqlAdapter with DataSet.. That is the reason error arosed

SqlDataAdapter da = new SqlDataAdapter("select * from tab", con); 

System.Data.DataSet ds = new System.Data.DataSet();
da.Fill(ds);


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Even though after filling sqladapter if you get same error then do as follows:
Possibly you can try this
GridView1.DataSource = ds.Tables[0].DefaultView;


or
GridView1.DataSource = ds.Tables["<tablename>"].DefaultView;</tablename>


Since the Datasource property of the Gridview is not able to find any datasources you are getting the error.And before binding please try and check if the dataset has tables or not.If it has tables,point to the specific table for the DataSource of the grid and then bind it.

Try this It should work


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response