Tôi có tình huống thực sự kỳ lạ. Tôi đã tạo trang aspx mới và không sử dụng bất kỳ đối tượng logic tùy chỉnh nào (tất cả mọi thứ được tạo bằng trình thuật sĩ trực quan) đã cố tạo chế độ xem lưới từ sqldatasource.GridView trống mặc dù sqldatasource có giá trị
Dữ liệu đến từ quy trình được lưu trữ, với tham số duy nhất có giá trị mặc định. khi tôi làm mới lược đồ hoặc nhấp vào "truy vấn thử nghiệm", tôi thấy các hàng kết quả và các trường GridView được tạo một cách cẩn thận. Nhưng khi tôi chạy trang không có khung nhìn lưới (nó chỉ đơn giản là trống rỗng - khi tôi thêm EmptyDataTemplate nó được hiển thị). Tôi đã thêm chức năng tùy chỉnh (trống) và DataBind, DataBinded và RowCreted, và chỉ các sự kiện databind và datavound được kích hoạt (mặc dù, như tôi đã viết - thủ tục được lưu trữ với các hàng trả về tham số mặc định của nó và .net có thể đọc chúng trong chế độ thiết kế)
Không có bất cứ điều gì "ưa thích" trong quy trình, tôi đã thực hiện việc này nhiều lần mà không có vấn đề gì. Tôi đã thử một lưu trữ công trình Mà thủ tục trong env sản xuất của chúng tôi và vẫn có những Emty cùng GridView
đây là mã
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TEST.aspx.cs" Inherits="site.TEST" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
AllowSorting="True" OnDataBinding="GridView1_DataBinding" OnDataBound="GridView1_DataBound"
OnRowCreated="GridView1_RowCreated">
<EmptyDataTemplate>
No Data Available
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="myStoredProcedure" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="val1" Name="par1" Type="String" />
<asp:Parameter Name="val2" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
và codebehind
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace site
{
public partial class TEST : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{//brake here
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{//brake here
}
protected void GridView1_DataBinding(object sender, EventArgs e)
{//brake here
}
protected void GridView1_DataBound(object sender, EventArgs e)
{//brake here
}
}
}
Bạn không thể tưởng tượng mình cảm ơn như thế nào :) – SimSimY
+1 Bạn vừa mới cứu tôi vài giờ! :) – meda
Cảm ơn. 6 năm sau, bạn đã giúp tôi :-) Không chắc chắn lý do tại sao MS làm điều đó theo mặc định để tạo ra mess. –