如何从窗体视图>编辑项目模板>文本框中获取值

本文关键字:文本 获取 项目 窗体 视图 编辑 | 更新日期: 2023-09-27 18:34:17

所以我有这个 FormView,它应该只有 1 条记录用于编辑:

    <asp:FormView ID="fmv_accountDetail" runat="server" DataKeyNames="UserID"
        DataSourceID="sds_accountDetail" DefaultMode="Edit" 
        emptydatatext="No employees found." 
        onitemcommand="fmv_accountDetail_ItemCommand"  >
        <EditItemTemplate>
            <asp:Label ID="lbl_UserID" runat="server" Text='<%# Eval("UserID") %>'  Visible="false"></asp:Label>
            <asp:Label ID="lbl_CustomerName" runat="server" Text='<%# Eval("customerName") %>'  Visible="false"></asp:Label>
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                CommandName="Update" Text="Update" />
            &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
        </EditItemTemplate>
    </asp:FormView>

如何在 C# 中获取lbl_CustomerName? 我想在页面上使用此值填充其他标签。

这是我一直在尝试的,但它说空错误异常:

(fmv_accountDetail.FindControl("lbl_CustomerName") as Label).Text;

如何从窗体视图>编辑项目模板>文本框中获取值

找到了问题,也很容易:

(fmv_accountDetail.Row.FindControl("lbl_CustomerName") as Label).Text;