我真的很奇怪的情況。 我已經創建了新的aspx頁面,並且沒有使用任何自定義邏輯對象(用視覺工作室嚮導創建的所有東西)嘗試從sqldatasource創建網格視圖。空gridview雖然sqldatasource有值
數據來自存儲過程,具有默認值的單個參數。當我刷新模式或單擊「測試查詢」時,我看到結果行和GridView字段被正確地創建。但是當我運行該頁面時,沒有網格視圖(它只是空的 - 當我添加EmptyDataTemplate時,它顯示)。我已經添加了自定義(空)函數和DataBind,DataBinded和RowCreted事件,並且只激發了數據綁定和datavound事件(儘管,正如我寫的 - 存儲過程的默認參數返回行和.net可以在設計模式下讀取它們)
程序中沒有任何「花哨」,我已經多次做這個,沒有任何問題。我試着在我們的生產ENV另一個存儲過程至極的作品,仍然得到了同樣的emty gridview的
這裏是代碼
<%@ 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>
和代碼隱藏
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
}
}
}
你無法想象我是多麼的感恩:) – SimSimY 2009-11-18 08:47:06
+1你剛剛救了我幾個小時! :) – meda 2013-07-02 19:14:44
謝謝。 6年後,你幫了我:-) 不知道爲什麼MS做默認的東西造成混亂。 – 2015-09-06 07:50:31