2014年7月13日 星期日

[RESOLVED] FormView.FindControl always null


Hi,


I have a FormView with an EditItemTemplate and I need to know if one of the controls has been populated.  If it has, I want to render it invisible and show another control instead.


I've tried the following:





...
runat="server" Text='<%# Bind("OnHoldReason") %>'>

Text='<%# Eval("OnHoldReason") %>'>

...


In the code behind I have:


protected void FormViewAlert_DataBound(object sender, EventArgs e)
{
Label lbl = FormViewAlert.Row.FindControl("lblOnHoldReason") as Label;
}

The Row property is always null.  I've tried it without referencing the row:


protected void FormViewAlert_DataBound(object sender, EventArgs e)
{
Label lbl = FormViewAlert.FindControl("lblOnHoldReason") as Label;
}

That doesn't work either; the control is always null.


I've also tried this in the ItemCreated event with the same negative results.


Any ideas?












This because default mode is readonly


Try this


    protected void FormViewAlert_ModeChanged(object sender, EventArgs e)
{
if (FormViewAlert.CurrentMode == FormViewMode.Edit)
{
Label lbl = FormViewAlert.FindControl("lblOnHoldReason") as Label;
}
}







Check with the answer of this post if it can help you.


http://forums.asp.net/t/1428282.aspx (check post which is marked as answer)



Thanks.  I'm sure I tried that before but it didn't work.  Seems it wants to, now.  Modern technology, eh?


沒有留言:

張貼留言