2015-02-11 33 views
0

我正在關注this的例子,我很難在gridview中顯示數據。當頁面加載時,它會到達GetData並返回值。在asp.net JQGrid不顯示數據(不可見)

如果在我填寫數據表並看到計數?dtResult.Rows.Count後立即窗口我得到1001。所以我知道我有數據。 但是,當我調試應用程序,我只是得到三個按鈕。我在這裏錯過了什麼?

這裏是aspx代碼:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="TestApp.test" %> 
<%@ Register Assembly="Trirand.Web" TagPrefix="trirand" Namespace="Trirand.Web.UI.WebControls" %> 
<!DOCTYPE html> 
<html lang="en-us"> 
<head id="Head1" runat="server"> 
<meta charset="utf-8"> 
<link rel="stylesheet" type="text/css" media="screen" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/themes/redmond/jquery-ui.css" /> 
<!-- The jQuery UI theme extension jqGrid needs --> 
<link rel="stylesheet" type="text/css" media="screen" href="/themes/ui.jqgrid.css" /> 
<!-- jQuery runtime minified --> 
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-2.0.3.min.js" type="text/javascript"></script> 
<!-- The localization file we need, English in this case --> 
<script src="/js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script> 
<!-- The jqGrid client-side javascript --> 
<script src="/js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script>  

<style type="text/css"> 
    body, html { font-size: 80%; }  
</style> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div>  
    <div id="message"> 

    <script type="text/javascript"> 

     function addRow() { 
      var grid = jQuery("#<%= JQGrid1.ClientID %>"); 
      grid.editGridRow("new", grid.addDialogOptions); 
     } 

     function editRow() { 
      var grid = jQuery("#<%= JQGrid1.ClientID %>"); 
      var rowKey = grid.getGridParam("selrow"); 
      var editOptions = grid.getGridParam('editDialogOptions'); 
      if (rowKey) { 
       grid.editGridRow(rowKey, editOptions); 
      } 
      else { 
       alert("No rows are selected"); 
      } 
     } 

     function delRow() { 
      var grid = jQuery("#<%= JQGrid1.ClientID %>"); 
      var rowKey = grid.getGridParam("selrow"); 
      if (rowKey) { 
       grid.delGridRow(rowKey, grid.delDialogOptions); 
      } 
      else { 
       alert("No rows are selected"); 
      } 
     } 
    </script> 

    <input type="button" onclick="addRow()" value="Add" /> 
    <input type="button" onclick="editRow()" value="Edit" /> 
    <input type="button" onclick="delRow()" value="Delete" /> 

    <trirand:jqgrid runat="server" ID="JQGrid1" 
     OnRowDeleting="JQGrid1_RowDeleting" 
     OnRowAdding="JQGrid1_RowAdding" 
     OnRowEditing="JQGrid1_RowEditing">   
     <Columns> 
      <trirand:JQGridColumn DataField="Addressbookid" Editable="false" PrimaryKey="true" /> 
      <trirand:JQGridColumn DataField="ClientName" Editable="true" /> 
      <trirand:JQGridColumn DataField="Clientno" Editable="true" /> 
      <trirand:JQGridColumn DataField="IndustryName" Editable="true" />    
     </Columns> 
     <ToolBarSettings ShowEditButton="true" ShowAddButton="true" ShowDeleteButton="true" /> 
     <EditDialogSettings CloseAfterEditing="true" Caption="The Edit Dialog" /> 
     <AddDialogSettings CloseAfterAdding="true" />    

    </trirand:jqgrid> 

    </div> 
    <br /><br /> 


</div> 
</form> 

這裏的隱藏代碼:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.SqlClient; 
using System.Data; 
using System.Configuration; 

namespace TestApp 
{ 
public partial class test : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     JQGrid1.DataSource = GetData(); 
     JQGrid1.DataBind(); 
    } 


    protected DataTable GetData() 
    { 
     if (Session["EditDialogData"] == null) 
     { 
      // Create a new Sql Connection and set connection string accordingly 
      SqlConnection sqlConnection = new SqlConnection(); 
      sqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings["Sandbox"].ConnectionString; 
      sqlConnection.Open(); 

      string sqlStatement = "Select * from voiceportal.dbo.clients_v"; 

      // Create a SqlDataAdapter to get the results as DataTable 
      SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlStatement, sqlConnection); 

      // Create a new DataTable 
      DataTable dtResult = new DataTable(); 

      // Fill the DataTable with the result of the SQL statement 
      sqlDataAdapter.Fill(dtResult); 

      Session["EditDialogData"] = dtResult; 

      return dtResult; 
     } 
     else 
     { 
      return Session["EditDialogData"] as DataTable; 
     } 
    } 
} 

}

我如何能解決這個問題有什麼建議?

謝謝

回答

1

我的兩分錢。

  1. 確保網格區域設置js文件位於正確的位置,並且可以很好地適用於您的瀏覽器。查看相關行: <script src="/js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script> 使用F12打開您的開發者控制檯,刷新頁面並在控制檯上查找下載的文件和錯誤消息,以確定是否執行順利。

  2. 仔細檢查您提供的數據是否與列配置匹配。特別注意駱駝套管。 .NET屬性以大寫字母開頭,它們是駱駝式的,但JSON數據通常以小寫字母開頭。這也取決於你是否使用任何轉換(如NewtonSoft和東西)。我不知道你的voiceportal.dbo.clients_v表中有什麼,請指定你的模式。在你的ASPX代碼AddressbookidClientno不是駱駝殼。他們不應該是AddressbookIdClientNo?取決於你的模式以及通過電線實際發生的事情。

+0

就是這樣。 'JavaScript'文件的路徑不正確。謝謝。 – smr5 2015-02-11 23:19:50