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!
Great - thanks for sharing - I am sure other people will find this useful. Indeed, Templated Columns provide a lot of flexibility and almost any scenario can be achieved using the technique you have described.
Thanks again.
Also, here is the VB.Net code for the C# stuff above...
Protected Sub UltraWebGrid1_InitializeRow(ByVal sender As Object, ByVal e As RowEventArgs) Dim cell As UltraGridCell = e.Row.Cells.FromKey("Discontinued") Dim column As TemplatedColumn = CType(cell.Column,TemplatedColumn) Dim cellItem As CellItem = CType(column.CellItems(e.Row.Index),CellItem) Dim checkBox As CheckBox = CType(cellItem.FindControl("CheckBox1"),CheckBox) If (e.Row.Index > 5) Then checkBox.Visible = false End If End Sub
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!
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; }}