ASP.NET Nested FormView

萝らか妹 提交于 2019-12-11 04:04:37

问题


I have this 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>

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?


回答1:


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;
    }
}


来源:https://stackoverflow.com/questions/6001812/asp-net-nested-formview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!