开发者

Can't find controls in FormView.InsertItemTemplate even on DataBound event

开发者 https://www.devze.com 2022-12-27 18:48 出处:网络
I have FormView in my page markup: <asp:FormView ruanat=\"server\" ID=\"FormView1\" DataSourceID=\"SqlDataSource1\" OnDataBinding=\"FormView1_DataBinding\" OnDataBound=\"FormView1_DataBound\">

I have FormView in my page markup:

<asp:FormView ruanat="server" ID="FormView1" DataSourceID="SqlDataSource1" OnDataBinding="FormView1_DataBinding" OnDataBound="FormView1_DataBound">
   <InsertItemTemplate>
      <uc:UserControl1 runat="server" ID="ucUserControl1" />
   </InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource runat="server" ID="SqlDataSource1" SelectCommand="EXEC someSP" />

It's code-behind WAS:

protected void FormView1_DataBound(object sender, EventArgs e)
{
   var c = FormView1.FindControl("ucUserControl1"); // returns null
}

BECAME:

protected void FormView1_DataBinding(object sender, EventArgs e)
{
   FormView1.ChangeMode(FormViewMode.Insert);
}

protected void FormView1_DataBound(object sender, EventArgs e)
{
   if (FormView1.CurrentMode = FormViewMode.Insert)
   {
      var c = FormView1.FindControl("ucUse开发者_如何转开发rControl1"); // returns null no more!
   }
}

In theory, I'm able to find control on FormView after it being data bound. But I'm not. Why?


If (FormView1.CurrentMode == FormViewMode.Insert)
      var c = FormView1.FindControl("ucUserControl1");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号