We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

CheckBox Column in GridGroupingControl


Hi!

I'm using the GridGroupingControl with several columns. One column is a boolean column and I want to use a Checkbox to set the boolean values.

How do I achieve this? Do I need to change the ItemTemplate and EditTemplate? How do I set and get the values from my datasource to/from the template?

See screenshot column 3.

Thanks
Jürgen


Attachment: table_bool_12f10b9c.zip

1 Reply

KN Kavitha Narayanan Syncfusion Team June 11, 2015 12:51 PM UTC

Hi Juergen,

Thanks for using syncfusion product.

Query 1: How do I achieve this? Do I need to change the ItemTemplate and EditTemplate?

We have achieved your requirement with the help of itemTemplate. We have set checkbox control to the ‘Discontinued’ column.

Please refer the below code snippets:

[ASPX]

<ItemTemplate>

<asp:CheckBox ID="cbRowBtnTemplate" Checked='<%#Eval("Discontinued")%>' runat="server" OnCheckedChanged="cbRowBtnTemplate_CheckedChanged" AutoPostBack="true"/>

</ItemTemplate>

Query 2: How do I set and get the values from my datasource to/from the template?

We can set and get the Boolean values to datasource with the help of  SQL update query, in which Boolean values will be updated in datasource.

Please refer the below code snippets:

[CS]

GridRow gridrow = (GridRow)checkbox.Parent.Parent.Parent;

        if (gridrow.DisplayElement.Kind != Syncfusion.Grouping.DisplayElementKind.ColumnHeader)

        {

          

            var discontinued = gridrow.Record.GetValue("Discontinued");

            var productID = gridrow.Record.GetValue("ProductID");

            if (checkbox != null)

            {

                if (checkbox.Checked == true)

                {

                    discontinued = true;

                 

                }

                else

                {

                    discontinued = false;

                }

                sqlconnection.Open();

// query to update checkbox value to Discontinued column

                sqlcommand = new SqlCommand("UPDATE Products SET Discontinued = '" + discontinued + "' WHERE ProductID = '" + productID + "'", sqlconnection);

                sqlcommand.ExecuteScalar();

                sqlconnection.Close();

            }

        }

    

For your reference, we have attached the sample.

Sample:sample.zip

Please let us know if you need any further assistance.

Thanks,
Kavitha Narayanan


Loader.
Up arrow icon