假设我从数据库中检索了一个DataSet。之后,我想在ASP.Net C#的ListView/GridView中显示。我怎样才能做到这一点?任何样品给我?如何在ListView/GridView中显示数据集
1
A
回答
4
试试这个
if(datasetObject.tables.count > 0)
{
GridView.DataSource = datasetObject;
GridView.DataBind();
}
else
{
lable.Text = "No Record Found";
}
1
使用GridView的DataBind()
方法来做到这一点。像
GridView.DataSource = ds;
GridView.DataBind();
1
将数据集设置为网格的DataSource属性值,然后调用DataBind()方法。
从MSDN
http://msdn.microsoft.com/en-us/library/fkx0cy6d.aspx
void Page_Load(Object sender, EventArgs e)
{
// This example uses Microsoft SQL Server and connects
// to the Northwind sample database. The data source needs
// to be bound to the GridView control only when the
// page is first loaded. Thereafter, the values are
// stored in view state.
if(!IsPostBack)
{
// Declare the query string.
String queryString =
"Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]";
// Run the query and bind the resulting DataSet
// to the GridView control.
DataSet ds = GetData(queryString);
if (ds.Tables.Count > 0)
{
AuthorsGridView.DataSource = ds;
AuthorsGridView.DataBind();
}
else
{
Message.Text = "Unable to connect to the database.";
}
}
}
假设AuthorsGridView是你的GridView控制的ID和GetData方法返回一个数据集与数据。
相关问题
- 1. 显示数据集中的数据?
- 2. 在datagrid中显示数据集?
- 3. 如何正确使用DataBinding,INotifyPropertyChanged,ListViewGridView
- 4. 如何在图表中显示Google健身数据集?
- 5. wpf:如何在网格视图中显示数据集?
- 6. 如何仅在UITableView中显示数据源的子集?
- 7. 如何在Symfony2中显示多个数据集
- 8. 显示数据集中的字节数
- 9. 显示的数据集
- 10. 如何在核心图中显示带数据点的数据集?
- 11. 如何在刺激中显示没有url数据库图像数据集
- 12. 如何在iPhone中显示YUV420P数据?
- 13. 如何在sql中显示行数据?
- 14. 如何在图中显示MySQL数据?
- 15. 如何在UITableView中显示JSON数据
- 16. 如何在sqlserver 2008中显示数据?
- 17. 如何在BarChart中显示数据Android
- 18. 如何在DataGridView中显示WMI数据
- 19. 如何在TextView中显示数据
- 20. 如何在JavaScript中显示数据?
- 21. 如何在listview中显示数据?
- 22. 如何在HTML中显示Json数据?
- 23. 如何在SSRS列中显示数据
- 24. 如何在视图中显示数据
- 25. 如何在UISegmentedControl中显示数据?
- 26. 如何在C#中显示JSON数据
- 27. 如何在TabPanel中显示Ext.List数据?
- 28. 如何在WPF中显示数据表?
- 29. 如何在TableviewCell中显示Json数据?
- 30. 如何在iphone中显示JSON数据?
这种简单的事情应该由谷歌搜索的解决方案也有数不胜数的例子在网上解决。 – 2011-12-15 13:01:19