ASP.NET FormView控件嵌套 [英] ASP.NET Nested FormView

查看:191
本文介绍了ASP.NET FormView控件嵌套的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的HTML。

<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
    <asp:FormView ID="FormView2" runat="server" DefaultMode="Insert" DataSourceID="SqlDataSource2">
       <asp:TextBox runat="Server" Text='<%# Eval("Terms") %>'></asp:TextBox>
    </asp:FormView>
</asp:FormView>

在code上面没有任何错误的作品,但我想条款在文本框中从FormView1的SqlDataSource1代替FormView2(SqlDataSource2)获取。我是缺少在这里?

The code above works without any error but I want to get terms in the textbox fetched from SqlDataSource1 of FormView1 instead of FormView2 (SqlDataSource2). What I am missing here?

推荐答案

您可以访问父对应视图的DataSource值在儿童FormView控件的值作为目前你正在做什么。但是,你设置值的另一种方式。如..

You can access the value of Parent formView DataSource value in child formview as what you are currently doing. But there is another way you set value. like..

protected void ChildFormWiew_DataBound(object sender, EventArgs e)
{
    if (ChildFormView.CurrentMode == FormViewMode.Edit)
    {
        TextBox txtTemrs = ParentFormView.FindControl("Terms") as TextBox;
        ((TextBox)ChildFormView.FindControl("Terms")).Text = txtTemrs.Text;
    }
}

这篇关于ASP.NET FormView控件嵌套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆