所以我有这个 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" />
<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;