문제

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 >
    }
}
도움이 되었습니까?

해결책 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

다른 팁

Try this one

string value = myControl.DataField;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top