Domanda

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 >
    }
}
È stato utile?

Soluzione 2

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

Altri suggerimenti

Try this one

string value = myControl.DataField;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top