PRB: DataGrid Control Does Not Display Correctly in .aspx Page (313156)
The information in this article applies to:
- Microsoft ASP.NET (included with the .NET Framework) 1.0
- Microsoft ASP.NET (included with the .NET Framework 1.1)
This article was previously published under Q313156 This article refers to the following Microsoft .NET
Framework Class Library namespace:
SYMPTOMS When you view an .aspx page that contains a DataGrid control, the data grid may not appear. Alternately, only the
header of the data grid may appear, but the data grid may not contain any data.
CAUSEData Grid Does Not Appear The data grid does not appear at all if:
- You do not set the DataSource property of the DataGrid control. -or-
- You do not call the DataBind method of the DataGrid control or the DataBind method of the Page object from your code.
Data Grid Header Appears But Data Grid Is Empty The data grid header appears, but the data grid does not contain
any data if:
- The data source does not contain any data.
-or-
- You do not fill the dataset that is bound to the DataGrid with data at run time.
NOTE: You must write code to explicitly fill the dataset so that the DataGrid is populated with data from the database at run time. You can do
this when you use the designer to add the DataAdapter object and to generate a dataset at design time.
This problem occurs because the .aspx page retrieves the
details of the header fields from the
DataSetName.xsd file. The
DataSetName.xsd file is created for each dataset
when you generate a dataset at the design time. This file contains the
Extensible Markup Language (XML) representation of the dataset. The .aspx page
retrieves the header field details from this file. Therefore, the data grid
header appears but the data grid is empty. RESOLUTIONData Grid Does Not Appear To resolve this problem, follow these steps:
- Set the DataSource property of the DataGrid to point to the appropriate data source. For example:
Visual Basic
DataGrid1.DataSource = dataSet11.Tables("Authors")
Visual C#
DataGrid1.DataSource = dataSet11.Tables["Authors"] ;
NOTE: If you programmatically retrieve the data from the data source,
assign the data source to the DataSource property of the DataGrid. - If you use the designer to add a DataAdapter to the Web form and to generate a dataset, open the DataGrid property page, and then select the appropriate DataSet or DataView object in the DataSource property.
- Call the DataBind method of the DataGrid control or the DataBind method of the Page object. For example:
Visual Basic
'Use one of the following lines.
'Page.DataBind()
DataGrid1.DataBind()
Visual C#
//Use one of the following lines.
//Page.DataBind();
DataGrid1.DataBind();
Data Grid Header Appears But Data Grid Is Empty To resolve this problem, follow these steps:
- Make sure your that your data source contains data and that
your query returns data.
- Use a DataAdapter to fill the dataset. For example:
Visual Basic
sqlDataAdapter1.Fill(dataSet11, "Authors")
Visual C#
sqlDataAdapter1.Fill(dataSet11,"Authors");
STATUSThis
behavior is by design.REFERENCES For more information about the DataGrid control and for samples that use this control, refer to the
following Microsoft Web sites:
Modification Type: | Major | Last Reviewed: | 10/30/2003 |
---|
Keywords: | kbDataBinding kbprb kbServerControls KB313156 kbAudDeveloper |
---|
|