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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid not displayed using Visual Studio.Net

Status
Not open for further replies.

croydon

Programmer
Apr 30, 2002
253
EU
I have started using Visual Studio.Net to create a Web application. Unfortunately, I have hit a problem.

I want to use a DataGrid on the WebForm to display records in an Access table. I have taken the following steps:

- Created an OleDbAdapter and pointed this to the relevant table.
- Generated a DataSet from the adapter
- Created a DataGrid on the WebForm using the DataSet as the data source

In Data Adapter Preview, the data is listed correctly when I press the Fill Dataset button (so presumably the link to the table is ok).

However, when I view the project in the Browser the DataGrid is not displayed (the other labels on the form are ok).

Any suggestions would be appreciated.
 
Where do you bind the DataGrid to it's DataSource?

Can you post code to help ease of diagnosis please...

Rhys
Thought out... Maybe,
Opinionated... Probably
But it is only an opinion!
 
Rhys,

I didn't code this manually, I used the DataGrid Property Builder. I chose the DataSource from the listbox (there was only the one dataset and 'unbound'). So the link to the DataSet was ok.

With regard to the .aspx.vb code, there is nothing included for the DataGrid other than the declaration:

Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

In the HTML, the following line is included:

<asp:DataGrid id=DataGrid1 style=&quot;Z-INDEX: 102; LEFT: 26px; POSITION: absolute; TOP: 84px&quot; runat=&quot;server&quot; DataSource=&quot;<%# DataSet21 %>&quot; DataKeyField=&quot;RoomType&quot; DataMember=&quot;tblRoomType&quot;>

Would I be right in thinking that populating the DataGrid has to be coded manually (using OleDbAdapter.Fill in Page Load?)?

Thanks.

Colin

 
Yes. You'll need to 'fill' the DataTable that your using as the DataGrid's DataSource, and bind the DataGrid to it's DataSource, (DataGrid's .Bind method), after this. Also, be aware of whether you need to renew the Data and DataGrid's data each post back or whether you should only be doing it on initial load...
I.E.

<CODE Type=c#>
// If it's a Post Back
if (IsPostBack)
{
// Do Something
}
// If it's not a Post Back
else if (!IsPostback)
{
// Do Something

}
</CODE>


Rhys
Thought out... Maybe,
Opinionated... Probably
But it is only an opinion!
 
Rhys,

Yes, I checked through some of my code from last year for populating a DropDownList and realised this.

As the data source was specified I would have thought that Visual Studio.Net would have been clever enough to make the control work automatically without any manual coding. Never mind.

Problem solved. Thanks for your help.

Colin
 
The datasource may have been specified but VS has no idea how that datasource (whether it's a collection, datareader or dataset) gets filled up with data.

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Zarcom,

Thanks for the info. I have it working now.

Colin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top