假設我從數據庫中檢索了一個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