FormView中EditItemTemplate的注意事项

html代码
<asp:FormView ID="bidForm" runat="server" DataKeyNames="BidId" OnItemInserted="form_ItemInserted" OnItemUpdated="form_ItemUpdated" OnItemDeleted="form_ItemDeleted"
           DataSourceID="bidDS">
            <HeaderTemplate><h1> Bid Details </h1></HeaderTemplate>
       
        <ItemTemplate>
        <table id="Table1" class="table" cellspacing="0">
        <tr>
            <th>Currency:</th>
            <td><%# Eval("Currency.Code") %></td>
            <td><asp:LinkButton ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" /></td>
        </tr>
        </table>            
       </ItemTemplate>
       <EditItemTemplate>
        <table id="Table2" class="table" cellspacing="0">
        <tr>
            <th>Currency:</th>
            <td><asp:DropDownList ID="DropCurrency" runat="server" SelectedValue='<%# Bind("CurrencyId") %>' DataValueField="CurrencyId" DataTextField="Code" DataSourceID="currencyDS">
</asp:DropDownList></td>
            <td><asp:LinkButton ID="btnUpdate" runat="server" Text="Update" CommandName="Update" />
              <asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" /></td>
        </tr>
        </table>            
       </EditItemTemplate>
                        
    </asp:FormView>


<asp:LinqDataSource ID="bidDS" runat="server"
        ContextTypeName="FactBaserDB" EnableInsert="true"
        EnableUpdate="True" TableName="Bids"
        AutoGenerateWhereClause="True">      
     <WhereParameters>
         <asp:Parameter Name="BidId" DefaultValue="2" Type="Int32" />
     </WhereParameters>      
    </asp:LinqDataSource>


<asp:LinqDataSource ID="currencyDS" runat="server"
        ContextTypeName="FactBaserDB" Select="new (CurrencyId, Code)"
        TableName="Currencies" ></asp:LinqDataSource>

注意
上面的table2控件如果写runat="server"后.则数据不会读取EditItemTemplate的里控件的值,尽管你用了<%# Bind("CurrencyId") %>,
InsertItemTemplate中也是一样.
所以在FormViewInsertItemTemplateEditItemTemplate里如果用到了table(里面有要获取的值时),此table不能设置runat="server".

posted on 2008-06-05 18:18  秋天  阅读(1668)  评论(1编辑  收藏  举报

导航