1

我试图弄清楚为什么我的列表视图在我构建解决方案时没有显示,但它显示在 Visual Studio 中。我错过了 HTML 中的一些语法吗?当我使用 Firebug 检查代码时,没有任何代码显示它试图呈现列表视图。

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(我用于搜索)显示了我想要的所有列标题。如果我遗漏了一些明显的东西,请告诉我!

谢谢你,格雷格

4

2 回答 2

1

您的列表视图数据源为空。如果 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
于 2012-07-20T23:54:44.280 回答
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/>");

然后根据需要调整参数。

希望这可以帮助。

于 2015-03-30T14:28:31.627 回答