I have an ASPxGridView
with a column containg ASPxTextBox
<dx:GridViewDataTextColumn Caption="Capacity" FieldName="Capacity" VisibleIndex="4" >
<DataItemTemplate>
<dxe:ASPxTextBox ID="txtCapacity" runat="server" Text='<%# Eval("Capacity") %>'>
</dxe:ASPxTextBox>
</DataItemTemplate>
</dx:GridViewDataTextColumn>
I added a button for saving the capacity.
I use GetRowValues(index, field_name)
to access other fields and FindRowCellTemplateControl(index, column, id)
to be able to get txtCapacity
's value. But the problem is, when paging is involved, I can't access the textboxes in other pages.
Any ideas a开发者_如何学编程bout this? Thanks
EDIT v.1
Here is my code where I invoke FindRowCellTemplateControl()
protected void btnSave_Click(object sender, EventArgs e)
{
List<Capacity> capacityList = new List<Capacity>();
for (int i = 0; gvCapacity.VisibleRowCount > i; i++)
{
Capacity c = new Capacity();
c.Id = (int)gvCapacity.GetRowValues(i, "Id");
ASPxTextBox txtCapacity = (ASPxTextBox)gvCapacity.FindRowCellTemplateControl(i, (GridViewDataColumn)gvCapacity.Columns["Capacity"], "txtCapacity");
c.Value = Convert.ToInt32(txtCapacity.Text);
capacityList.Add(c);
}
//Save Capacity
//...
}
The ASPxGridView creates template controls for an active page only. So, it is impossible to get a reference to the non-existing controls via the FindRowCellTemplateControl method.
See the http://www.devexpress.com/issue=Q341997 discussion in the DX support center to learn more on how to solve this issue.
Regardless my comment on your question, and if I got your question right then,
you have an ASPxButton
and you want when Click
it to get all Capacities
inside your ASPxGridView
try this:
protected void ASPxButton1_Click(object sender, EventArgs e)
{
//Loop throug all Pages
for (int i = 0; i < ASPxGridView1.PageCount; i++)
{
//Select current page
ASPxGridView1.PageIndex = i;
//Loop through all rows inisde the page
for (int J = 0; J < ASPxGridView1.SettingsPager.PageSize; J++)
{
//Get currnt TextBox
DevExpress.Web.ASPxEditors.ASPxTextBox txtbox =
ASPxGridView1.FindRowCellTemplateControl(J,
(DevExpress.Web.ASPxGridView.GridViewDataColumn)ASPxGridView1.Columns["Capacitiy"],
"txtCapacity") as DevExpress.Web.ASPxEditors.ASPxTextBox;
//Do your logic here
}
}
}
I'm still encourage you to get your data through your underlying datasource
精彩评论