我在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 >
}
}
答案 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
}
谢谢, 菲利佩·平托