0

ListViewコードビハインドから入力、フィールドの作成方法を知りたいです。この例を見ましたが、 ListViewsフィールドを作成する唯一の方法がテーブルを使用することであるかどうかを確認したいと思います。そうでない場合、それを行う別の方法は何でしょうか?ListView次のように、データソースのみを入力してみました。

ListView1.DataSource = ds;
ListView1.DataBind();

しかし、それは私にエラーを与えました:

ItemTemplateは、ListView'ListView1'で定義する必要があります。

使用するための最良の方法は何ListViewですか?エラーは私が使用した場合にのみ発生しますListView1.DataBind();

PS:表示するのに必要な行は1つだけなので、誰かがよりも使用するためのより良いコントロールを持っている場合ListView、私は読んでいます。

アップデート

今私はこのようにしようとしています:

<asp:ListView ID="ListView1" runat="server">
    <LayoutTemplate>
       <table border="0" cellpadding="1">
           <tr style="background-color: #E5E5FE">
              <th align="left"><asp:LinkButton ID="lnkResp" runat="server"></asp:LinkButton></th>
              <th align="left"><asp:LinkButton ID="lnkProj" runat="server"></asp:LinkButton></th>
              <th align="left"><asp:LinkButton ID="lnkFunc" runat="server"></asp:LinkButton></th>
              <th<></th>
           </tr>
       </table>
    </LayoutTemplate>
    <ItemTemplate>
       <tr>
          <td><asp:Label runat="server" ID="lblResp"><%#Eval("responsavel") %></asp:Label></td>
          <td><asp:Label runat="server" ID="lblProj"><%#Eval("projeto") %></asp:Label></td>
          <td><asp:Label runat="server" ID="lblFunc"><%#Eval("funcionalidade") %></asp:Label></td>
       </tr>
     </ItemTemplate>
</asp:ListView>

しかし、新しいエラーが発生 しました。

An item placeholder must be specified on ListView 'ListView1'.
Specify an item placeholder by setting a control's ID property to "itemPlaceholder".
The item placeholder control must also specify runat="server".

4

1 に答える 1

4

では、タグLayoutTemplateに が必要です。<asp:PlaceHolder runat="server" ID="itemPlaceholder" />table

 <LayoutTemplate>
   <table border="0" cellpadding="1">
       <tr style="background-color: #E5E5FE">
          <th align="left"><asp:LinkButton ID="lnkResp" runat="server"></asp:LinkButton></th>
          <th align="left"><asp:LinkButton ID="lnkProj" runat="server"></asp:LinkButton></th>
          <th align="left"><asp:LinkButton ID="lnkFunc" runat="server"></asp:LinkButton></th>
          <th<></th>
       </tr>
       <asp:PlaceHolder runat="server" ID="itemPlaceholder" />
   </table>
</LayoutTemplate>
于 2013-03-11T14:47:19.813 に答える