2017-02-24 52 views
0

我使用.NET是新的Web开发时遇到的结合,从业务逻辑的数据表中的问题。我基本上试图动态地填充表。数据在asp.net结合:列表视图

表中我要填充

<asp:ListView ID="processList" runat="server" 
      DataKeyNames="procName" GroupItemCount="1" 
      ItemType="SerMon.RemoteProcess" SelectMethod="fetchFromQueue"> 
      <EmptyDataTemplate> 
       <table > 
        <tr> 
         <td>No data was returned.</td> 
        </tr> 
       </table> 
      </EmptyDataTemplate> 
      <EmptyItemTemplate> 
       <td/> 
      </EmptyItemTemplate> 
      <GroupTemplate> 
       <tr id="itemPlaceholderContainer" runat="server"> 
        <td id="itemPlaceholder" runat="server"></td> 
       </tr> 
      </GroupTemplate> 
      <ItemTemplate> 
       <td runat="server"> 
        <table id="myTable" class="table table-striped table-hover "> 
         <thead> 
          <tr> 
           <th>#</th> 
           <th>Process</th> 
           <th>Status</th> 
           <th>Machine</th> 
          </tr> 
         </thead> 
         <tbody> 
          <tr> 
           <td>1</td> 
           <td> 
            <asp:Label runat="server" ID="lblId"><%#: Item.ProcName%></asp:Label></td> 
           <td> 
            <asp:Label runat="server" ID="Label1"><%#: Item.Procstatus%></asp:Label></td> 
           <td> 
            <asp:Label runat="server" ID="Label2"><%#: Item.mcName%></asp:Label></td> 
          </tr> 
          <tr> 
         </tbody> 
        </table> 

        </p> 
       </td> 
      </ItemTemplate> 

     </asp:ListView> 

方法被称为填充表

public List<RemoteProcess> fetchFromQueue() 
    { 
     List<RemoteProcess> pl = new List<RemoteProcess>(); 
     foreach (CloudQueueMessage message in queue.GetMessages(5, TimeSpan.FromMinutes(1))) 
     { 
      Debug.Write(message.AsString); 
      RemoteProcess m = JsonConvert.DeserializeObject<RemoteProcess>(message.AsString); 
      pl.Add(m); 
      //queue.DeleteMessage(message); 
     } 
     return pl; 
    } 

时,将生成表,但世界上没有数据的列表视图。另外一些奇怪的原因,产生五个表(这始终是等于在GetMessage函数指定的号码)

+1

我觉得你的情况这将是更好地使用'GridView'控制,而不是'ListView'控制。 – VDWWD

+0

尝试删除'GroupItemCount =“1”'以避免5个表格。 –

+0

@ChetanRanpariya没试,试过了。不起作用 – NeuralLynx

回答

0

如果GroupTemplate需要你在ListView我不知道。你得到多个表的原因是你已经在项目模板中定义了表头和行。 ItemTemplate应该只有项目显示的结构。 LayoutTemplate应该具有数据外观的整体布局结构。

我已经改变了的ListView如下这使它看起来像一个真正的表。

<asp:ListView ID="processList" runat="server" 
    DataKeyNames="procName" 
    ItemType="WebApplication1.Models.RemoteProcess" SelectMethod="fetchFromQueue"> 
    <EmptyDataTemplate> 
     <table> 
      <tr> 
       <td>No data was returned.</td> 
      </tr> 
     </table> 
    </EmptyDataTemplate> 
    <EmptyItemTemplate> 
     <td /> 
    </EmptyItemTemplate> 
    <LayoutTemplate> 
     <table runat="server" id="table1"> 
      <thead> 
       <tr runat="server"> 
        <th>#</th> 
        <th>Process</th> 
        <th>Status</th> 
        <th>Machine</th> 
       </tr> 
       <tr id="itemPlaceholder" runat="server"></tr> 
      </thead> 
     </table> 
    </LayoutTemplate> 
    <ItemTemplate> 
     <tr runat="server"> 
      <td>1</td> 
      <td> 
       <asp:Label runat="server" ID="lblId"><%#: Item.procName%></asp:Label></td> 
      <td> 
       <asp:Label runat="server" ID="Label1"><%#: Item.Procstatus%></asp:Label></td> 
      <td> 
       <asp:Label runat="server" ID="Label2"><%#: Item.mcName%></asp:Label></td> 
     </tr> 
    </ItemTemplate> 
</asp:ListView> 

请注意这里,我已经删除了GroupTemplate并设置相关的它,因为我不知道如何对数据进行分组。

这将有助于解决您的问题。

+0

工作正常!没有获取多个表,但数据仍未填充。 PROCNAME和机列是空的,但是状态栏始终是0。我有双重检查正在传递的对象,它包含了所需的数据,它只是没有显示。 – NeuralLynx

+0

检查您是否从源获取数据?在'return pl'上放置一个断点并调试代码。查看'pl'中填充了什么值。 –