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.
Unfortunately, activation email could not send to your email. Please try again.

Row Selection Bound to Checkboxes

Thread ID:

Created:

Updated:

Platform:

Replies:

74540 Jun 18,2008 12:21 PM Feb 11,2010 07:33 AM ASP.NET Web Forms (Classic) 8
loading
Tags: GridGroupingControl
Administrator [Syncfusion]
Asked On June 18, 2008 12:21 PM

Hello,

Using 'TableOptions.ListBoxSelectionMode = SelectionMode.MultiSimple' provides very good built in functionality. I just want to modify this slightly:

- The built-in selection behavior is such that the user clicks anywhere on a row to select it, and selection is displayed by highlighting the row.

- I want to use a column of checkboxes for row multi-row selection: The user would select a row via it's cooresponding checkbox. The row would not be highlighted after selection, rather the checkbox is used as a visual indicator that the row has been selected.

Currently, I have a databound gridgrouping control with an unbound column of checkboxes. How do I "hook them up" to the default selection behavior? Or, Is there an easier way to add row selection checkboxes to the grid?

this.GridGroupingControl1.TableDescriptor.UnboundFields.Add("Selection");
this.GridGroupingControl1.TableDescriptor.VisibleColumns.Move(this.GridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("Selection"), 0);
this.GridGroupingControl1.TableDescriptor.VisibleColumns.Add("Selection");
var chkBox = new CheckBox();
var template = new CustomItemTemplate();
template.AddControl(chkBox);
this.GridGroupingControl1.TableDescriptor.Columns.FindByMappingName("Selection").ItemTemplate = template;

Thanks,
Robert Claypool, Nashville, TN





Rajarajeswari S [Syncfusion]
Replied On June 18, 2008 02:12 PM

Hi Robert,

Thanks for using Syncfusion products.

You can easily achieve your requirement through "RowBtnTemplate". The control which is place dinside the template, will before on each and every row. If we place the Checkbox inside the template and set the ListBoxSelectionMode property to MuliSelect, then by clicking on the checkbox will select the row accordingly.

Please refe the below code snippet which illustartes this:


$TableDescriptor AllowNew="False" AllowFilter="False">
$RowBtnTemplate>
$asp:CheckBox ID="cbRowBtnTemplate" runat="server" OnCheckedChanged="cbRowBtnTemplate_CheckedChanged"
onclick="CheckAll(this);" AutoPostBack="true">
$/asp:CheckBox>
$/RowBtnTemplate>

Note:

Here "$" is used instead of "<".

Please refer the sample from the below link which illustrates the above:

http://websamples.syncfusion.com/samples/Grid.Web/6.2.0.40/Grid_Web_CheckboxTemp/main.htm


Please let me know if this helps you out.

Regards,
Raji


Administrator [Syncfusion]
Replied On June 20, 2008 09:26 AM

Thank you for your timely response. The example was very helpful.

I have just a few follow up questions:
- How might I remove the top checkbox that executes CheckAll()?
- I noticed that the example does not work in FireFox 3.0. Do you know when the components will be updated to fix that?

Sincerely, RC


Administrator [Syncfusion]
Replied On June 20, 2008 05:27 PM


Please use the following code to hide the checkbox in the header,

this.GridGroupingControl1.QueryCellStyleInfo += delegate(object sender, GridTableCellStyleInfoEventArgs args)
{
if ( e.Style.CellType == "RowHeaderCell" )
{
if ( e.TableCellIdentity.ColIndex == 0 && e.TableCellIdentity.RowIndex == 1 )
e.Style.CellType = "Static";
}
};

The Style event would change the type for the first cell that is shown in the column header and thus removing the template from it.



Administrator [Syncfusion]
Replied On June 20, 2008 05:39 PM

this.GridGroupingControl1.QueryCellStyleInfo += delegate(object sender, GridTableCellStyleInfoEventArgs args)
{
if (args.Style.CellType == "RowHeaderCell")
{
if (args.TableCellIdentity.ColIndex == 0 && args.TableCellIdentity.RowIndex == 2)
args.Style.CellType = "Static";
}
};


Rajarajeswari S [Syncfusion]
Replied On June 23, 2008 02:03 PM

Hi Robert,

1.How might I remove the top checkbox that executes CheckAll()?

Through QueryCellStyleInfo event we can filter the Grid cells according to the cell type, and we can have the CheckBox for a particular cells. Please refer the below code snippet which illustrates this:

protected void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
//Look for the RecordField and AlternateField Cell.
if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
{

System.Web.UI.WebControls.CheckBox cb = new CheckBox();
cb.ID = "CheckBox1";
cb.Checked = true;
//Here we adding the DropDownListBox programatically using ITemplate Interface
TemplateClass mytemp = new TemplateClass(cb);
this.GridGroupingControl1.TableDescriptor.RowBtnTemplate = mytemp;
}
}

Please refer the sample from the below link which illustartes the above:

http://websamples.syncfusion.com/samples/Grid.Web/6.2.0.40/Grid_Web_ChTemp/main.htm

2. Support in FireFox 3.0

We have no plans on providing support for FireFox 3.0.

Please let me know if you have any other concerns.

Regards,
Raji



Carlos Guanes
Replied On October 29, 2009 12:47 PM

using your previous sample
http://websamples.syncfusion.com/samples/Grid.Web/6.2.0.40/Grid_Web_CheckboxTemp/main.htm

How can I map that column to datacolumn?


right now I have under my columns definition:
AllowDropDownCell="False" AllowGroupByColumn="False" AllowSort="False">


OnCheckedChanged="tosend_CheckedChanged"
Checked="<%# GetChkBoxSendValue(Container) %>" AutoPostBack="True" />


CheckBoxOptions-UncheckedValue="0" />









and what I'm trying to do is to add at the column title a check box, so the user can click there to autocheck all records or do it one per one....


Thanks

Carlos

Lakshmi Narasimman G [Syncfusion]
Replied On December 2, 2009 10:23 AM

Hi Carlos,

Thank you for your interest in Syncfusion Products.

We suggest you to use javascript to customize the header row checkbox to check CheckBox in all rows.Please refer online demo from the follwing link

http://samples.syncfusion.com/ASPNET/7.4.0.20/Web/Grid.Grouping.Web/samples/3.5/Template/CheckedTemplate/cs/checkboxtemplate.aspx?args=12

Thanks,
Lakshmi Narasimman G

Mohammad Rafiq
Replied On February 11, 2010 07:33 AM

Is it Possible to do Windows forms?.
i need some sample code to select all checkbox in grid databound control.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;