下面是在AspxGridView控件中查找子控件的方法示例:
假如现在有一个ASPX页面有一个AspxGridView控件,代码如下:
<dxwgv:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" KeyFieldName="CategoryID" OnHtmlRowPrepared="OnHtmlRowPrepared" >
<Columns >
<dxwgv:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0" / >
<dxwgv:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1" / >
<dxwgv:GridViewDataTextColumn FieldName="Description" VisibleIndex="2" >
<DataItemTemplate >
<asp:TextBox ID="txtDescription" runat="server" >
</asp:TextBox >
</DataItemTemplate >
</dxwgv:GridViewDataTextColumn >
</Columns >
</dxwgv:ASPxGridView >
现在我需要找到grid的Description列中的txtDescription控件,并为该控件设置初始值,可在AspxGridView控件的OnHtmlRowPrepared方法中实现,具体代码如下:
protected void OnHtmlRowPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e) {
ASPxGridView grid = (ASPxGridView)sender;
TextBox txtDescription =
(TextBox)grid.FindRowCellTemplateControl(e.VisibleIndex, (GridViewDataColumn)grid.Columns["Description"], "txtDescription");
txtDescription.Text = "这是初始值!";
}
AspxGridView的更多教程,请查看本站:
AspxGridView使用教程