• 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".
  • 相关阅读:
    如何清理云之家的用户
    修改BOS的开发商标识
    华军纯净下载
    3333
    取得当前目录
    达梦数据库常用知识
    idea远程debugger
    ubuntu 16.04 安装TurtleBot3 ROS功能包
    树莓派4B安装ubuntu server系统
    ubuntu 安装openCV
  • 原文地址:https://www.cnblogs.com/qfb620/p/1214673.html
Copyright © 2020-2023  润新知