即使在 DataBound 事件上也无法在 FormView.InsertItemTemplate 中找到控件
我的页面标记中有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)