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!
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
Hi,
What type is the column that you are trying to cast? Is it TemplatedCloumn or UltraGridColumn of type checkbox?
I'm using the same VB code shown above and I'm getting a typecast error...
Unable to cast object of type 'Infragistics.WebUI.UltraWebGrid.UltraGridColumn' to type 'Infragistics.WebUI.UltraWebGrid.TemplatedColumn'
Any thoughts?
Hi
I want to add 2 drop down lists in a single cell. for that what should i do. Can anyone provide me the sample code to have a know how about it?
Any little help will be appreciated greatly
Thanks
Regards
Sohaib qazi
I also was getting a type cast error, but it was because the Intellisense didn't recognize TemplatedColumn and was defaulting to TemplateColumn (asp.net - notice the missing "d").
when i try to typecast it to TemplatedColumn it throws a error, mentioning unable to cast from gridcolumn to templatedcolumn. I am using hte same code mentioned abve (C#)
any comments?
UltraGridCell cell1 = e.Row.Cells.FromKey("Trend"); TemplatedColumn column1 = (TemplatedColumn)cell1.Column; CellItem cellItem = (CellItem)column1.CellItems[e.Row.Index]; Image img = (Image)cellItem.FindControl("Image1"); img.Attributes.Add("onMouseDown", "GridCellImageMouseDown(" + img + ")"); img.Attributes.Add("onDragStart", "InitiateDragForResult()");