2012-05-03 33 views
0

我在formview中有以下內容,我希望能夠顯示信息,如果有人進行更改,我應該通過單擊更新來更新此信息。我對asp.net開發相當新,我該怎麼做?我一直有例外,說frm1正在期待editmode。如何在Formview上同時使用EditItemTemplate和ItemTemplate?

在此先感謝

<<asp:Formview D="FormView1" runat="server" DataSourceID="SqlDesc" ID="frm1"> 
    <ItemTemplate> 
     <table> 
     <tr> 
      <td> 
       Description:<br /> 
      </td> 
      <td style=""> 
       <asp:TextBox ID="DescTbox" runat="server" Width="450px" TextMode="MultiLine" Text='<%# Bind("Description") %>' Enabled="True" Rows="4"></asp:TextBox>     
      </td>     
     </tr> 
     <tr> 
     <td></td> 
     <td> 
      <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update"> </asp:Button> 
     </td>     
     </tr> 
    </table> 
    </ItemTemplate> 
    <EditItemTemplate> 
    <table> 
     <tr> 
      <td> 
       Description:<br /> 
      </td> 
      <td style=""> 
       <asp:TextBox ID="DescTbox" runat="server" Width="450px" TextMode="MultiLine" Text='<%# Bind("Description") %>' Enabled="True" Rows="4"></asp:TextBox>     
      </td>     
     </tr> 
     <tr> 
     <td></td> 
     <td> 
      <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update"> </asp:Button> 
     </td>     
     </tr> 
    </table> 

    </EditItemTemplate> 
    </asp:Formview> 

回答

1

<Itemtemplate>應提供如果可能,數據的只讀視圖,其中更新只在<EditItemTemplate>可用。然後您需要將該行置於編輯模式,以便通過在表上設置EditRowIndex來編輯行。

+1

對不起您能不能給任何的例子嗎? – CPM

0

我不得不添加DefaultMode作爲編輯和使用的EditItemTemplate代替ItemTemplate

<asp:Formview ID="FormView1" runat="server" DefaultMode="Edit" > 
     <EditItemTemplate> ... 
     </EditItemTemplate> <asp:Formview> 

感謝

相關問題