您无法直接访问 EditItemTemplate 控件。您可以在 HtmlRowCreated 事件中访问它们,如下所示:
if (e.RowType != GridViewRowType.InlineEdit) return;
ASPxTextBox txtBox = ASPxGridView1.FindEditRowCellTemplateControl(ASPxGridView1.Columns["Name"]
as GridViewDataColumn, "ASPxTextBox1") as ASPxTextBox;
检查文档 http://documentation.devexpress.com/#AspNet/CustomDocument3922关于访问模板中包含的控件
可以将 ASPxLabel.NamingContainer 属性强制转换为 GridViewEditItemTemplateContainer,并通过 GridViewEditItemTemplateContainer.Text 属性获取列值。
但我喜欢technique of using the Init/Load event handler.
当网格切换到编辑模式时,将引发 ASPxLabel.Load 事件。检查这篇文章使用 Init/Load 事件处理程序的一般技术 http://www.devexpress.com/Support/Center/p/K18282.aspx寻求实施帮助。
[ASPx]
<dxe:ASPxTextBox ID="txtName" runat="server" Width="170px" OnInit="txtName_Init">
</dxe:ASPxTextBox>
[C#]
ASPxTextBox txtName;
protected void txtName_Init(object sender, EventArgs e)
{
txtName = (ASPxTextBox)sender;
GridViewEditFormTemplateContainer container = txtName.NamingContainer as GridViewEditFormTemplateContainer;
// You can remove the if statement, and try to insert a new record. You'll catch an exception, because the DataBinder returns null reference
if (!container.Grid.IsNewRowEditing)
txtName.Text = DataBinder.Eval(container.DataItem, "CategoryName").ToString();
}
更新事件:
protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
e.NewValues["CategoryName"] = txtName.Text;
}
已经有一个问题了——ASPxGridView - 如何在 EditItemTemplate 中查找控件 http://www.devexpress.com/Support/Center/p/Q344248.aspx在 DevExpress 论坛上。