2017-06-11 22 views
-1

這是我的代碼。ListView中的Jquery數據表不工作

輸出是「表中沒有可用數據」。我非常感謝並提前致謝。我試圖把數據表放在listview的Layout模板中。

<table id="example" class="display"> 
    <thead> 
     <tr> 
      all columns 
     </tr> 
    </thead> 
    <tfoot> 
     <tr> 
      all columns 
     </tr> 
    </tfoot> 
    <tbody> 

     <asp:ListView ID="lstfinance" runat="server"> 
      <LayoutTemplate> 
       <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder> 
      </LayoutTemplate> 
      <ItemTemplate> 
       <tr> 
        <td>Charde Marshall</td> 
        <td>Regional Director</td> 
        <td>San Francisco</td> 
        <td>36</td> 
        <td>2008/10/16</td> 
        <td>$470,600</td> 

       </tr> 
      </ItemTemplate> 
     </asp:ListView> 
    </tbody> 
</table> 
<script> 
    $(document).ready(function() { 
     $('#example').DataTable(); 
    }); 
</script> 
+0

你有沒有看着加載頁面的原始HTML看看它是否正確,數據是否真的被推送到頁面? – Bindrid

+0

除了位於標籤內的數據之外,所有內容都被加載。 –

回答

0

您的代碼不工作,因爲它沒有數據綁定,所以它是空的。這裏是一個解決方案,將幫助你,直到它的數據綁定

所以在後面的代碼:

protected void Page_Load(object sender, EventArgs e) 
    { 
     lstfinance.DataBind(); 
    } 

而在內容頁:

<table id="example" class="display"> 
    <thead> 
     <tr> 
      <th>Name</th> 
      <th>Position</th> 
      <th>City</th> 
      <th>Age</th> 
      <th>Start</th> 
      <th>Salary</th> 
     </tr> 
    </thead> 
    <tfoot> 
     <tr> 
      <th>Name</th> 
      <th>Position</th> 
      <th>City</th> 
      <th>Age</th> 
      <th>Start</th> 
      <th>Salary</th> 
     </tr> 
    </tfoot> 
    <tbody> 

     <asp:ListView ID="lstfinance" runat="server"> 
      <LayoutTemplate> 
       <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder> 
      </LayoutTemplate> 


      <EmptyDataTemplate> 
        <tr> 
        <td>Charde Marshall</td> 
        <td>Regional Director</td> 
        <td>San Francisco</td> 
        <td>36</td> 
        <td>2008/10/16</td> 
        <td>$470,600</td> 
       </tr> 
      </EmptyDataTemplate> 


      <ItemTemplate> 
        <tr> 
        <td>Charde Marshall</td> 
        <td>Regional Director</td> 
        <td>San Francisco</td> 
        <td>36</td> 
        <td>2008/10/16</td> 
        <td>$470,600</td> 
       </tr> 
      </ItemTemplate> 
     </asp:ListView> 
    </tbody> 
</table> 
+0

非常感謝。 –