2012-07-20 70 views
1

我想弄清楚为什么我的列表视图不会显示,当我构建我的解决方案,但它显示在Visual Studio中。我错过了HTML中的一些语法?当我使用Firebug检查代码时,没有任何代码显示它尝试渲染列表视图。VB.NET ASPX - Listview不显示?在Visual Studio中显示

ASPX页面:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm4.aspx.vb" Inherits="WebApplication2.WebForm4" 
MasterPageFile="obj/Site1.Master" ViewStateMode="Enabled" %> 

    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="ContentArea"> 
     <fieldset> 
    <fieldset> 
     <legend style="text-align: center">Vendor Results Screen</legend> 
     <table width="100%"> 
      <tr> 
       <td align="center"> 
        <asp:Label ID="FilterBy" runat="server" Text="Filter By: " Font-Bold="true" Font-Size="Large"></asp:Label> 
        <asp:DropDownList ID="dropDownFieldName" runat="server"> 
         <asp:ListItem Text="FieldName" Value="DocumentProviderID">  </asp:ListItem> 
         <asp:ListItem Text="Status" Value="Status"></asp:ListItem> 
         <asp:ListItem Text="FieldName" Value="PDFNumber">  </asp:ListItem> 
        </asp:DropDownList> 
        <br /> 
       </td> 
      </tr> 
      <tr> 
       <td align="center" style="height: 34px"> 
        <asp:Label ID="SearchBy" runat="server" Text="Search By: " Font-Bold="true" Font-Size="Large"></asp:Label> 
        <asp:TextBox ID="searchBox" runat="server"></asp:TextBox> 
        <asp:Button ID="SearchButton" runat="server" Text="Search" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <table width="100%"> 
         <tr> 
          <td> 
           <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"> 
            <asp:ListItem Value="10">10</asp:ListItem> 
            <asp:ListItem Value="25">25</asp:ListItem> 
            <asp:ListItem Value="50" Selected="True">50</asp:ListItem> 
            <asp:ListItem Value="75">75</asp:ListItem> 
            <asp:ListItem Value="100">100</asp:ListItem> 
           </asp:DropDownList> 
          </td> 
          <td align="right"> 
           <asp:Button ID="ExportToExcel" runat="server" Text="Export To Excel" /> 
          </td> 
         </tr> 
        </table> 
       </td> 
      </tr> 
      <asp:ListView ID="ListView1" runat="server" EnableViewState = "true" Visible="true"> 
       <LayoutTemplate> 
        <table cellpadding="2" width="100%" border="1" runat="server" id="tblProducts"> 
         <tr id="Tr1" runat="server"> 
          <th id="Th1" runat="server"> 
           Field Name 
          </th> 
          <th id="Th2" runat="server"> 
           Type 
          </th> 
          <th id="Th3" runat="server"> 
           XML Path 
          </th> 
          <th id="Th4" runat="server"> 
           Vendor Path 
          </th> 
          <th id="Th5" runat="server"> 
           Status 
          </th> 
          <th id="Th6" runat="server"> 
           Comments 
          </th> 
          <th id="Th7" runat="server"> 
           Edit 
          </th> 
          <th id="Th8" runat="server"> 
           Forms 
          </th> 
          <th id="Th9" runat="server"> 
           CU Specific 
          </th> 
         </tr> 
         <tr runat="server" id="itemPlaceholder" /> 
        </table> 
        <asp:DataPager runat="server" ID="DataPager1" PageSize="50"> 
         <Fields> 
          <asp:NumericPagerField ButtonCount="10" CurrentPageLabelCssClass="CurrentPage" NumericButtonCssClass="PageNumbers" 
           NextPreviousButtonCssClass="PageNumbers" NextPageText=" Next " PreviousPageText=" Previous " /> 
         </Fields> 
        </asp:DataPager> 
       </LayoutTemplate> 
       <ItemTemplate> 
        <tr id="Tr2" runat="server"> 
         <td> 
          <asp:Label ID="FieldName" runat="Server" Text='<%#Eval("FLD_NM") %>' /> 
         </td> 
         <td> 
          <asp:Label ID="Type" runat="Server" Text='<%#Eval("DATA_TYPE_CD") %>' /> 
         </td> 
         <td> 
          <asp:Label ID="XMLPath" runat="Server" Text='<%#Eval("WS_XML_PATH_TX") %>' /> 
         </td> 
         <td> 
          <asp:Label ID="VendorPath" runat="Server" Text='<%#Eval("FLD_NM") %>' /> 
         </td> 
         <td> 
          <asp:DropDownList ID="Status" runat="Server" /> 
         </td> 
         <td> 
          <asp:TextBox ID="Comments" runat="Server" MaxLength="100" /> 
         </td> 
         <td> 
          <asp:LinkButton ID="EditButton" runat="Server" Text="Edit" CommandName="Edit" /> 
         </td> 
         <td> 
          <asp:Label ID="Forms" runat="Server" Text='<%#Eval("FLD_NM") %>' /> 
         </td> 
         <td> 
          <asp:Label ID="CUSpecific" runat="Server" Text='<%#Eval("FLD_NM") %>' /> 
         </td> 
        </tr> 
       </ItemTemplate> 
       <EditItemTemplate> 
        <tr style="background-color: #ADD8E6"> 
         <td> 
          <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />&nbsp; 
          <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" /> 
         </td> 
         <td> 
          <asp:TextBox ID="FieldName" runat="server" Text='<%# Bind("FLD_NM") %>' MaxLength="50" /><br /> 
         </td> 
         <td> 
          <asp:TextBox ID="DataType" runat="server" Text='<%# Bind("DATA_TYPE_CD") %>' MaxLength="50" /><br /> 
         </td> 
        </tr> 
       </EditItemTemplate> 
        </asp:ListView> 
       </table> 
      </fieldset> 
     </fieldset> 
    </asp:Content> 

VB:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
If (Not IsPostBack) Then 
    dataTable() 
    Dim dataT As DataTable = dsData 
    dsData = ViewState("Table") 
    ListView1.DataSource = dataT.AsDataView 
    ListView1.DataBind() 
    'ListView1.Sort("FLD_NM", SortDirection.Descending) 
    dropDownFieldName.DataSource = dsData.Columns 
    dropDownFieldName.DataBind() 
End If 
End Sub 

这就是我运行VB,我不相信,VB是问题,因为我可以把一个断点,并查看表。另外,我的dropdownFieldName(我用于搜索)显示我想要的所有列标题。请让我知道,如果我错过了明显的东西,请!

谢谢 格雷格

+0

in this line'dsData = ViewState(“Table”)'视图状态可能为空 - 或者你在哪里做到了? – Aristos 2012-07-20 21:34:39

回答

1

您为ListView数据源为空。如果LisView数据源为空,则服务器将不呈现列表视图。我证实了这一点通过添加以下代码服务器端进入的Page_Load:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    If (Not IsPostBack) Then 

     Dim dt As New System.Data.DataTable 
     dt.Columns.Add(New System.Data.DataColumn("FLD_NM", GetType(System.Int32))) 
     dt.Columns.Add(New System.Data.DataColumn("DATA_TYPE_CD", GetType(System.String))) 
     dt.Columns.Add(New System.Data.DataColumn("WS_XML_PATH_TX", GetType(System.String))) 

     Dim row As System.Data.DataRow 
     row = dt.NewRow() 
     row.Item("FLD_NM") = 1 
     row.Item("DATA_TYPE_CD") = "A" 
     row.Item("WS_XML_PATH_TX") = "C:\TEMP\TEMP.XML" 
     dt.Rows.Add(row) 

     ListView1.DataSource = dt 
     ListView1.DataBind() 

    End If 
End Sub 
0

我不知道要连接,或者如果您使用的是SQL查询/ SP什么数据源。我遇到了同样的问题,我发现从VS到IIS时,我的查询参数在绑定之前将不同的值传递给存储过程(与页面呈现无关)。当我传递用户名时,问题就出现了。

如果你认为你的数据源可能是罪魁祸首(这是我的情况)尝试在你的页面加载插入下面的代码,并查看结果:

 Response.Write("Application code executed using: ");  
     Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name + "<br/>"); 

     Response.Write("Is User Authenticated: "); 
     Response.Write(User.Identity.IsAuthenticated.ToString() + "<br/>"); 

     Response.Write("Authentication Type, if Authenticated: "); 
     Response.Write(User.Identity.AuthenticationType + "<br/>"); 

     Response.Write("Application code executed using: "); 
     Response.Write(User.Identity.Name + "<br/>"); 

     Response.Write("Environment UserName: "); 
     Response.Write(Environment.UserName + "<br/>"); 

然后根据需要调整参数。

希望这会有所帮助。