- Home
- Forum
- ASP.NET Web Forms (Classic)
- Row Selection Bound to Checkboxes
Row Selection Bound to Checkboxes
- Jun 18, 2008 04:21 PM UTC
- Feb 11, 2010 12:33 PM UTC
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
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
SIGN IN To post a reply.
8 Replies
RS
Rajarajeswari S
Syncfusion Team
June 18, 2008 06:12 PM UTC
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
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
AD
Administrator
Syncfusion Team
June 20, 2008 01:26 PM UTC
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
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
AD
Administrator
Syncfusion Team
June 20, 2008 09:27 PM UTC
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.
AD
Administrator
Syncfusion Team
June 20, 2008 09:39 PM UTC
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";
}
};
{
if (args.Style.CellType == "RowHeaderCell")
{
if (args.TableCellIdentity.ColIndex == 0 && args.TableCellIdentity.RowIndex == 2)
args.Style.CellType = "Static";
}
};
RS
Rajarajeswari S
Syncfusion Team
June 23, 2008 06:03 PM UTC
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
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
CG
Carlos Guanes
October 29, 2009 04:47 PM UTC
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
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:
Checked="<%# GetChkBoxSendValue(Container) %>" AutoPostBack="True" />
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
LN
Lakshmi Narasimman G
Syncfusion Team
December 2, 2009 03:23 PM UTC
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
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
MR
Mohammad Rafiq
February 11, 2010 12:33 PM UTC
Is it Possible to do Windows forms?.
i need some sample code to select all checkbox in grid databound control.
i need some sample code to select all checkbox in grid databound control.
SIGN IN To post a reply.
- 8 Replies
- 5 Participants
-
AD Administrator
- Jun 18, 2008 04:21 PM UTC
- Feb 11, 2010 12:33 PM UTC