Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid binding problem not showing any data.

Status
Not open for further replies.

Trebor100

Programmer
Mar 14, 2006
90
GB
Hi all,

I've got a basic webform with a datagrid control on it. the column collection is setup with 6 columns contained in the course table however the following code does not populate any data into the control.

string SelectCmdString = "SELECT * FROM Course";
string conString = System.Configuration.ConfigurationSettings.AppSettings["SQLConnectionString"];
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(SelectCmdString, conString);
DataSet myDataSet = new DataSet();
mySqlDataAdapter.Fill(myDataSet,"Listing");
DataGrid1.DataSource = myDataSet.Tables["Listing"];
DataGrid1.DataBind();

Its odd to me as from hunting around on tut net i can't see anything that i have missed out.

cheers all.
 
Just to eliminate the obvious… was there data in the database table (sorry if this is a dumb question), if yes did the data make it to the table "Listing" ?

Age is a consequence of experience
 
there is data in the table and have looped through the listing table all of which is populated correctly......

im stuck :-(
 
You say Webform..

Where are you populating the DataGrid?
Is the Datagrid.Visible parameter set?

K
 
The population is done on page_load. when the webform is run the datagrid is displayed with only the column headings displayed as per how they were setup in the columns collection within the workspace at design time.
 
Right, leaving everyhting else as it is, what happens if you right click on the datagrid, and turn on "Create Columns Automatically at Runtime "

Im assuming that you arent calling DataGrid1.DataBind(); anywhere else in your code?

Is the DataGrid the same name as the one on the page - you havent added 2 to the page, and then deleted the wrong one or anythinkg silly like that have you? (Sorry if this is back to basics, but start from 1st principles and all that)
 
With the create columns automatically at runtime flag set the datagrid outputs the 6 columns i have created in the columns collection with column headings only followed by another 6 columns from the Table "Listing" which have the data populated.

DataBind is only called once and there is only one datagrid on the page. No problem on the back to basics Kalisto as im sure im doing something really stupid :)
 
ok, so the data is populated in the auto generated columns?

When you manually define the columns (presumably to se the headings?) do you set the bindings that map the columns to the fileds in the data table?

DataGrid (Right Click)-> PropertyBuilder -> Columns are the Data Fields set to the Column names as returned from the database?

K
 
okay its offical - im an idiot.

Problem solved. When i'd created the columns in the column collection i had done template column rather than bound column. thats gotta go in my top ten of all time muppet things to have done displacing managing to get a twiglet through my lip :)

cheers for the help Kalisto - i'm going to go hide for being that thick on this one :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top