GridView控件在ASP.NET中不使用或不显示数据 [英] GridView in ASP.NET is not displaying with or without data

查看:299
本文介绍了GridView控件在ASP.NET中不使用或不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加一个GridView和放大器;然后显示来自SQL Server数据库中包含数据。问题是,在GridView未在浏览器有或没有数据显示。

下面是我的code:

 < ASP:GridView控件ID =GridAllStore=服务器的AutoGenerateColumns =FALSEWIDTH =100%ViewStateMode =已启用>

 公共部分类AdminPanel:System.Web.UI.Page
{
    storelocatorDataSetTableAdapters.storedbTableAdapter tastore =新storelocatorDataSetTableAdapters.storedbTableAdapter();
    storelocatorDataSetTableAdapters.View_1TableAdapter taview =新storelocatorDataSetTableAdapters.View_1TableAdapter();    清单< storelocatorDataSet.storedbRow> lststore =新的List< storelocatorDataSet.storedbRow>();
    清单< storelocatorDataSet.View_1Row> lstview =新的List< storelocatorDataSet.View_1Row>();
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        lstview = taview.GetData()了ToList()。
        GridAllStore.DataSource = lstview;
    }
}


解决方案

我认为问题是,你还没有定义的任何要显示的列。你当你设置的AutoGenerateColumns 为false,以明确定义的列。

要确保基本的工作集的AutoGenerateColumns 为true:

 < ASP:GridView控件ID =GridAllStore=服务器的AutoGenerateColumns =真WIDTH =100%ViewStateMode =已启用>

使用的AutoGenerateColumns 设置为true,数据源分配的,而的DataBind()叫,你应该开始看到一些数据。一旦你开始看到数据,你可以定义特定列要显示。

由于您只需要在网格上绑定的第一个页面加载,利用 Page.IsPostBack 状态:

 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    如果(!Page.IsPostBack)
    {
        GridAllStore.DataSource = lstview;
        GridAllStore.DataBind();
    }
}

I'm adding a GridView & then showing data in it from a SQL Server database. The problem is that the GridView is not displaying in the browser with or without data.

Here is my code:

<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; 
    }
}

解决方案

I think the problem is that you haven't defined any columns to display. You have to explicitly define the columns when you set AutoGenerateColumns to false.

To make sure that the basics are working set AutoGenerateColumns to true:

<asp:GridView ID="GridAllStore"  runat="server" AutoGenerateColumns="true" Width="100%"  ViewStateMode="Enabled">

With AutoGenerateColumns set to true, the datasource assigned, and DataBind() called, you should start seeing some data. Once you start seeing the data, you can define the specific columns you want to display.

Since you only need to bind the grid on the first page load, utilize the !Page.IsPostBack condition:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        GridAllStore.DataSource = lstview;
        GridAllStore.DataBind();
    }
}

这篇关于GridView控件在ASP.NET中不使用或不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆