【发布时间】:2012-05-04 13:14:48
【问题描述】:
我正在添加一个 GridView,然后在其中显示来自 SQL Server 数据库的数据。问题是 GridView 没有在浏览器中显示有或没有数据。
这是我的代码:
<asp:GridView ID="GridAllStore" runat="server" AutoGenerateColumns="False" Width="100%" ViewStateMode="Enabled">
public partial class AdminPanel : System.Web.UI.Page
{
storelocatorDataSetTableAdapters.storedbTableAdapter tastore = new storelocatorDataSetTableAdapters.storedbTableAdapter();
storelocatorDataSetTableAdapters.View_1TableAdapter taview = new storelocatorDataSetTableAdapters.View_1TableAdapter();
List<storelocatorDataSet.storedbRow> lststore = new List<storelocatorDataSet.storedbRow>();
List<storelocatorDataSet.View_1Row> lstview = new List<storelocatorDataSet.View_1Row>();
protected void Page_Load(object sender, EventArgs e)
{
lstview = taview.GetData().ToList();
GridAllStore.DataSource = lstview;
}
}
【问题讨论】:
-
我想你忘了给
GridAllStore.DataBind()打电话 -
您要么必须将 AutoGenerateColumns 设置为 true,要么将列提供为您要显示的 Bound- 或 TemplateFields。无论哪种方式,您都必须 DataBind irt。
-
这是您对
GridView的完整标记吗? -
仍然没有显示数据。实际上 gridview 从一开始就没有显示在浏览器中。我认为添加数据源将解决问题。 :(