Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1923
Make cell checkbox
posted

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!

Parents
No Data
Reply
  • 28464
    posted

    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;
        }
    }

Children