FormView.FindControl(): object reference error

后端 未结 2 1956
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 18:10

I have a formview that has several textboxes inside of tr/td\'s. I\'m trying to get the textboxes by using the .FindControl method but it\'s coming back null. The FormView

相关标签:
2条回答
  • 2020-12-19 18:42

    Call DataBind(); first. Then FindControl()

    0 讨论(0)
  • 2020-12-19 18:51

    abatishchev's answer is right, although I found this variation a bit neater: it avoids having to call DataBind() explicitly.

    <asp:FormView ID="fvMember" runat="server" DataSourceID="tblMembers" DefaultMode="Insert" OnDataBound="DataBound">...</asp:FormView>
    

    protected void DataBound(object sender, EventArgs e)
    {
        if (fvMember.CurrentMode == FormViewMode.Edit)
        {
            Label lblSubmit = fvMember.FindControl("lblSubmit") as Label;
            ...
        }
    }
    
    0 讨论(0)
提交回复
热议问题