asp.net - ASP 存储过程到 GridView

标签 asp.net data-binding stored-procedures gridview dataset

我正在尝试使用现有的存储过程来填充 GridView 。

首先,我执行存储过程并使用 SqlAdapter 将其放入数据集中。我知道这是有效的,因为 DataSet.Tables[0] 包含我的数据。但是,当我创建 GridView 并将数据绑定(bind)到 GridView 时,没有显示任何内容。

这是绑定(bind)GridView的代码:

DataSet ds = Execute_spr();
GridView testGridView = new GridView();

if (ds.Tables.Count > 0)
{
   testGridView.DataSource = ds.Tables[0].AsEnumerable();
   testGridView.DataBind();
}

这是 .aspx 页面中我的 gridview 的代码:

<asp:GridView ID="testGridView" runat = "server" AutoGenerateColumns = "true" />

知道我可能做错了什么吗?

编辑:我尝试过不使用 AsEnumerable() 并使用 .DefaultView 的 ds.Tables[0]

最佳答案

为什么要重新初始化 Gridview 行

GridView testGridView = new GridView();

在您的代码中创建一个名为“testGridView”的 protected 成员,删除上面的行,您可能会开始有所收获...

关于asp.net - ASP 存储过程到 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3055047/

相关文章:

asp.net - 通过 jQuery ajax 绑定(bind) GridView

asp.net - 如何加速 AZURE 上部署的 .NET MVC 站点?

c# - 如何返回一个空字符串?

xaml - Xamarin.Forms "databind"Xaml 中的单个值 <x :Array type ="{x:Type x:String}">

c# - 当我的 wpf 绑定(bind)验证失败并且包含面板不再可见时,如何摆脱红色矩形?

stored-procedures - 使用 Entity Framework Core 2 将原始 SQL 映射存储过程结果到 POCO/DTO

Mysql 使用 Limit 使用占位符动态构建查询,如何在存储过程中创建它

asp.net - 母版页使用母版页和继承

c# - Eval(),只能在数据绑定(bind)控件错误的上下文中使用。为什么会这样?我该怎么办?

在存储过程中调用时,MYSQL SELECT 语句返回 null