1

テーブル表示をより細かく制御できるように、 aGridViewを aに変換しようとしています。ListView

ここGridViewで定義されているように正常に動作し、データを正しく表示します。

<asp:GridView ID="gvService" runat="server"
    AllowPaging="True"
    AutoGenerateColumns="False"
    DataKeyNames="ID"
    DataSourceID="objService">
    <Columns>
        <asp:BoundField DataField="ID" HeaderText="ID" />
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="ServiceType" HeaderText="Type" />
    </Columns>
</asp:GridView>

これを に変換するListViewと、ページに HTML がまったくレンダリングされません。私はそれらを並べて配置しましたGridViewが、作品ListViewは表示されません。

<asp:ListView ID="lvService" runat="server"
    DataSourceID="objService">
    <LayoutTemplate>
        <table>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Type</th>
        </tr>
        <tr id="itemPlaceholder" runat="server"></tr>
        </table>
    </LayoutTemplate>
    <ItemTemplate>
        <tr>
            <td><%# Eval("ID") %></td>
            <td><%# Eval("Name") %></td>
            <td><%# Eval("ServiceType") %></td>
        </tr>
    </ItemTemplate>
    <AlternatingItemTemplate>
        <tr>
            <td><%# Eval("ID") %></td>
            <td><%# Eval("Name") %></td>
            <td><%# Eval("ServiceType") %></td>
        </tr>
    </AlternatingItemTemplate>
</asp:ListView>

こちらがObjectDataSource

<asp:ObjectDataSource ID="objService" runat="server"
    EnablePaging="true"
    TypeName="My.Data.DataSource.ServiceDataSource" DataObjectTypeName="My.Data.Service.ServiceSearch"
    SelectMethod="Search"
    SelectCountMethod="SearchCount">
    <SelectParameters>
        <asp:ControlParameter ControlID="tbSearch" Name="Search" PropertyName="Text" Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>

ここで基本的な何かが欠けているように感じます。なぜGridView移入するのにListViewしないのかについての考えはありますか?

コード ビハインドでコントロールを手動でDataBind()する必要がありますか?

4

1 に答える 1