2017-06-11 20 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

非常感谢。 –