I have a link button inside a templated column that I need to change the visibility based on the data. I've tried:
{
CellItem ci = (CellItem)col.CellItems[0];
but archive always points to the SAME linkbutton... the one in the first row. Am I missing something? thanks!
You can hook custom event handlers in the various events of the nested controls inside the template and hide/show/populate them based on certain criteria. In the example below. I am hiding all dropdowns with the exception of the dropdown in the third row:
<igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Height="200px" Width="325px" DataSourceID="AccessDataSource1" > <Bands> <igtbl:UltraGridBand> <Columns> <igtbl:TemplatedColumn> <CellTemplate> <asp:DropDownList runat="server" ID="DropDownList1" OnInit="DropDownList1_OnInit"> </asp:DropDownList> </CellTemplate> </igtbl:TemplatedColumn> </Columns> </igtbl:UltraGridBand> </Bands> ...</igtbl:UltraWebGrid> protected void DropDownList1_OnInit(object sender, EventArgs e) { DropDownList dropDownList = sender as DropDownList; CellItem parentCell = (CellItem) dropDownList.NamingContainer; if (parentCell.Cell.Row.BandIndex != 3) { dropDownList.Visible = false; } }
I like your solution. However, I have to change a few controls in the templated column so I went with:
CellItem ci = (CellItem)col.CellItems[e.Row.Index];
LinkButton archive = (LinkButton)ci.FindControl("btnArchiveTrackForm");
and continuing to use ci.FindControl for each control I need to change.
Thanks for the great idea though.