1
所以我有这个FormView控件应该只对编辑1个记录:如何从formView-> EditItemTemplate-> Textbox中获取价值?
<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;
我觉得你有什么应该工作好的,只要FormView有数据并且已经被数据绑定。如果没有数据,FindControl(..)可能会返回null。然而,当数据源将被数据绑定时,我无法记住我的头顶。尝试在使用FindControl之前在FormView上调用DataBind()? – Balthy