asp.net从formview中的dynamiccontrol实体数据库字段获取值

时间:2014-03-11 16:25:00

标签: asp.net dynamic webforms formview

我在aspx中有以下代码:

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

我在后面的代码中如何在此DynamicControl中获取DataField的值(例如DataField Value =&#34; Ball&#34;)?

我试过这个但是没有工作:

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 个答案:

答案 0 :(得分:0)

试试这个

string value = myControl.DataField;

答案 1 :(得分:0)

我明白了:

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
}

谢谢, 菲利佩·平托