Datagrid Display Not Working

C

Cindy

Hello. For some reason, I am able to "connect" to the Northwind
database whenever I use the wizard; however, when I run the
application, my datagrid does not display. Here are the exact steps I
am taking to try to get this to run:

1)New Project -->ASP.NET Application
2) From the Server Explorer, drag the Northwind Employees table onto
the WebForm1.aspx design view. SqlConnection1 and SqlDataAdapter1 are
created.
3) From the Toolbox, drag the Datagrid control onto the WebForm1.aspx
web page.
4) Click on SqlDataAdapter1 box, select "Configure Data Adapter," and
fill out the settings for my server -- server name is the only one,
check "Use Windows Integrated Security," select the Northwind database,
and click on Test Connection. Succeeded. (Funny thing: On the
"Advanced" tab, none of the permissions are checked and I can't change
them.)
5)Click next and select "Use SQL Statements" for the rest of the
wizard.
6) Keep standard query generated out of the Employees table. ("SELECT
EmployeeID, LastName, FirstName, Title, TitleOfCourtesy, BirthDate,
HireDate, Address, City, Region, PostalCode, Country, HomePhone,
Extension, Photo, Notes, ReportsTo, PhotoPath FROM Employees")
7) Finish.
8)Click on Generate Dataset. It creates Dataset11.
9) Click on the Datagrid and use the dropdown in "Datasource" to select
Dataset11.

RUN.

The explorer page is blank, even though I can see the column names in
the DESIGN mode. What is going on?

Cindy
 
L

learndotnet

You need to fill your dataset.
By default, a data adapter does not fill a dataset. The "Generate
Dataset" you are talking about only creates a dataset with "Strongly
Typed" tables and columns, which means your dataset has strong names
for the data in it.

To fill your dataset with data, go to the page_load event and insert
the code:

sqldataAdapter1.Fill(dataset11) ' VB, change for c#
datagrid1.Databind() ' This line ensures that every page load causes
the data to bind to the datagrid

Ideally you would wrap the above 2 lines of code in:

if Not Page.IsPostback then
end if

This is because your datagrid might use paging. There's a walkthrough
on datagrids in MSDN help. You need to do a little more work to get
paging to work, but not much.

Steve
 
C

Cindy

Thanks! That worked perfectly!

You need to fill your dataset.
By default, a data adapter does not fill a dataset. The "Generate
Dataset" you are talking about only creates a dataset with "Strongly
Typed" tables and columns, which means your dataset has strong names
for the data in it.

To fill your dataset with data, go to the page_load event and insert
the code:

sqldataAdapter1.Fill(dataset11) ' VB, change for c#
datagrid1.Databind() ' This line ensures that every page load causes
the data to bind to the datagrid

Ideally you would wrap the above 2 lines of code in:

if Not Page.IsPostback then
end if

This is because your datagrid might use paging. There's a walkthrough
on datagrids in MSDN help. You need to do a little more work to get
paging to work, but not much.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top