Search code examples
asp.netdynamicwebformsformview

asp.net getting value from dynamiccontrol entity database field inside formview


I have the following code in aspx:

<asp.DynamicControl ID="ArticleName" runat="server" DataField="Name" Mode="Edit"/>

How in code behind i get the value of DataField in this DynamicControl (for example DataField Value = "Ball" ) ?

I have tried this but doesn't work:

protected void FormView1_Load(object sender, EventArgs e)
{
    DynamicControl myControl = (DynamicControl)FormView1.FindControl("ArticleName");
    if (myControl != null)
    {
        // Now What ???
        //string st = myControl.< I need help here >
    }
}

Solution

  • I got it :

    protected void FormView1_Load(object sender, EventArgs e)
    {
        var ctrl = FormView1.FindFieldTemplate("name") as IBindableControl;
        OrderedDictionary entityValues = new OrderedDictionary();
    
        entityValues.Add("name", null); // I have to initialize before
        ctrl.ExtractValues(entityValues); // Get values from FormView in this case only the article name field
    
        string myVal = entityValues["name"].ToString(); // This is what i want
    }
    

    Thanks, Filipe Pinto