2012-03-01 76 views
0

我在Asp.net 4.0中有一個ListView控件C# 我正在嘗試使默認模式=編輯模式與文本框。所以我拿了Item Template(默認模板)並用TextBox替換了我的數據綁定標籤。 它工作正常。除文本框外只適用於其他行。因此,一半的行是Page Load的文本框,一半的Roes仍然是標籤。這裏是我的代碼:在默認編輯模式下創建一個ListView控件

 <ItemTemplate> 
     <tr style=""> 
      <td> 
      <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' /> 
      </td> 
      <td> 

        <asp:TextBox ID="DiscountPercentageTextBox" runat="server" 
        Text='<%# Bind("DiscountPercentage") %>' /> 
      </td> 
      <td> 

      <asp:TextBox ID="CashTextBox" runat="server" Text='<%# Bind("Cash") %>' /> 
      </td> 
     </tr> 
    </ItemTemplate> 
     <LayoutTemplate> 
    <table> 
     <thead> 
      <tr> 
       <th>Title </th> 
       <th>DiscountPercentage</th> 
       <th>Cash</th> 
      </tr> 
     </thead> 
     <tbody> 
      <asp:PlaceHolder runat="server" ID="itemPlaceholder" /> 
     </tbody> 
    </table> 
</LayoutTemplate> 

這裏是結果:

enter image description here

你明白嗎?每隔一行都是一個文本框。我需要所有行爲文本框。我究竟做錯了什麼?

+0

人們仍然使用Webforms?! – Jack 2012-03-01 20:55:56

回答

0

呵呵,你有沒有定義一個AlternatingItemTemplate? ListVIew沒有智能將原始字段設置爲標籤....

嘗試將ALternatingItemTemplate作爲ItemTemplate,如果沒有定義。

+0

是的!謝謝你做到了!綠色複選標記! – 2012-03-01 21:10:16

相關問題