I add a templatedcolumn in an UltraWebGrid.and add some button in this templatedcolumn.
now,I want to find the control in this templatedcolumn in InitializeRow event.
how to code it ?
Can I ask why this has to be so difficult to get to? Is there some reason (other than developers didn't code it that way) I cannot have access to the FindControl method from f the e.Row object when I am in the RowInitialize event?
Look at these two examples. The first using normal ASP.NET Grid, the second using UltraWebGrid just attempting to get access to a DropDownList control while binding data.
protected void aspnetgrid_OnItemDataBound(object sender, DataGridItemEventArgs e){ var ddlControl = (DropDownList)e.Item.FindControl("dropDownListControl");}
protected void ultragrid_OnInitializeRow(object sender, RowEventArgs e){ var ddlControl = ((DropDownList)((CellItem)((TemplatedColumn)e.Row.Cells.FromKey("ddlContainer").Column).CellItems[e.Row.Index]).FindControl("dropDownListControl"));}
Why does it have to be buried that deeply? I think at any of the logical points of Row, Cells, Column etc. there could have been access to the FindControl method to save me a LOT of needless casting/typing.Do people using the UltraWebGrid only bind directly to controls and never have a need to manipulate controls during the data binding event?If so, then I guess I'm doing it "wrong" all these years.
Just wanted to follow-up with one additional example in C# and applicable for InitializeRow:
TemplatedColumn col = (TemplatedColumn)e.Row.Cells.FromKey("dropDownContainer").Column;CellItem ci = (CellItem)col.CellItems[e.Row.Index];DropDownList archive = (LinkButton)ci.FindControl("dropDownListID"
More info can be found here:
http://forums.infragistics.com/forums/p/11465/43344.aspx#43344
The trick is to get to the CellItem of the respective cell and proceed with FindControl from there. It really depends on how/where you need this implemented, but in any case, here is some sample code that could be useful:
Dim control As Control Dim tc As TemplatedColumn Dim radio As RadioButton