Is there a way to make a cell a checkbox cell without making the entire column of type checkbox? I'm converting a winforms dialog to the web and this functionality is possible with the UltraWinGrid...but I can't figure it out in the UltraWebGrid. thanks heaps!
Hello,
This is possible (though a bit tricky and requires some custom coding) through the use of templated columns. Inside the templated column CellTemplate you can use any HTML content you wish, including CheckBoxes. Then, in the InitializeRow event you can get a reference to the checkbox and hide it or show it depending on your run-time criteria with code (set Visible to true / false).
In the example below, I am hiding all checkboxes on rows with indices > 5.
<igtbl:TemplatedColumn BaseColumnName="Discontinued" DataType="System.Boolean" IsBound="true" Key="Discontinued"> <CellTemplate> <asp:CheckBox runat="server" ID="CheckBox1" /> </CellTemplate> </igtbl:TemplatedColumn>protected void UltraWebGrid1_InitializeRow(object sender, RowEventArgs e){ UltraGridCell cell = e.Row.Cells.FromKey("Discontinued"); TemplatedColumn column = (TemplatedColumn)cell.Column; CellItem cellItem = (CellItem) column.CellItems[e.Row.Index]; CheckBox checkBox = (CheckBox) cellItem.FindControl("CheckBox1"); if (e.Row.Index > 5) { checkBox.Visible = false; }}
thanks! this worked brilliantly...To further help the situation, Rows that don't have a checkbox have any range of values...and so to make this work I had a template column with a key of VALUE_DISPLAY and then in the InitializeRow event I applied logic and either set the checkbox or a value...to get this to work though...i made the following...
<CellTemplate> <asp:CheckBox runat="server" ID="CheckBox1" /> <asp:Literal runat="server" ID="Literal1" /></CellTemplate>
If you hide the checkbox and the real value is null...the cell doesn't display correctly, but simple put a into the literal and all is happy!