即使在 DataBound 事件上也无法在 FormView.InsertItemTemplate 中找到控件

发布于 2024-08-29 20:36:05 字数 1107 浏览 3 评论 0原文

我的页面标记中有 FormView

<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" />

它是代码隐藏 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("ucUserControl1"); // returns null no more!
   }
}

理论上,我能够找到对 的控制>FormView 数据绑定后。但我不是。为什么?

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("ucUserControl1"); // returns null no more!
   }
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-09-05 20:36:05
If (FormView1.CurrentMode == FormViewMode.Insert)
      var c = FormView1.FindControl("ucUserControl1");
If (FormView1.CurrentMode == FormViewMode.Insert)
      var c = FormView1.FindControl("ucUserControl1");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文