This is a migrated thread and some comments may be shown as answers.

Select all and content row checkboxes mutually exclusive?

11 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Naresh
Top achievements
Rank 1
Naresh asked on 10 Jul 2009, 10:10 AM
Hi,
 i am using radgrid with checkboxes  (GridClientSelectColumn), i want to obtain the functionality that :
If click on "Selct all" other checkboxes(content rows) should be disabled, and unchecking it shouls enable the content rows (im my case enabling the check boxes).
And how can I see whether the "select all" is checked? (for any actions like save/delete)

is it possible with gridclientselectcolumn? if not how can i achieve it?
regards
Naresh

11 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 10 Jul 2009, 10:42 AM
Hello Naresh,

You can try out the following to disable/enable checkboxes in grid rows ehen the select all header checkbox is checked/unchecked:
aspx:
<telerik:GridClientSelectColumn UniqueName="SelectColumn">                    
</telerik:GridClientSelectColumn> 

c#:
 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridHeaderItem) 
        { 
            GridHeaderItem header = (GridHeaderItem)e.Item; 
            CheckBox chk = (CheckBox)header["SelectColumn"].Controls[0]; 
            chk.AutoPostBack = true
            chk.CheckedChanged += new EventHandler(chk_CheckedChanged); 
        } 
    } 
 
    void chk_CheckedChanged(object sender, EventArgs e) 
    { 
        CheckBox headerchk = (CheckBox)sender; 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            if (headerchk.Checked) 
            { 
                ((CheckBox)item["SelectColumn"].Controls[0]).Enabled = false
            } 
            else 
            { 
                ((CheckBox)item["SelectColumn"].Controls[0]).Enabled = true
            } 
        } 
    } 

To check if the selectall checkbox is checked on save/delete:
c#:
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "Save")// or Delete 
        { 
            GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0]; 
            CheckBox chk = (CheckBox)headerItem["SelectColumn"].Controls[0]; 
            if(chk.Checked) 
            { 
               // code here 
            } 
        }   
     } 

Thanks
Princy.
0
Naresh
Top achievements
Rank 1
answered on 13 Jul 2009, 08:30 AM
when i do this:
 if (headerchk.Checked) 
            { 
                ((CheckBox)item["SelectColumn"].Controls[0]).Enabled = false
            } 
            else 
            { 
                ((CheckBox)item["SelectColumn"].Controls[0]).Enabled = true
            } 
the checkboxe are disabled, but still i can check/uncheck those by click on the row itself. Its because of the property: RadGrid.ClientSettings.Selecting.AllowRowSelect = True
And I can't set it to false because that property is required to use 'GridClientSelectColumn' feature.

How can i disable that row-click-select feature when those check boxes are disabled?

regards,
Naresh


0
Accepted
Princy
Top achievements
Rank 2
answered on 13 Jul 2009, 08:45 AM
Hello Naresh,

Check out the following code library submission which demonstrates on how to disable row selection on row click but select grid rows only when a GridClientSelectColumn check box is clicked. Thus, when the checkbox is disabled the rows does not get selected.
ClientSideSelectColumn - Disallow other selection

Thanks
Princy.

0
Bill
Top achievements
Rank 2
answered on 19 Apr 2010, 11:42 PM
It works a little to well for me - it's disabling sorting and grouping as well.
0
Bill
Top achievements
Rank 2
answered on 20 Apr 2010, 02:18 PM
Worse still - the next time there is a postback the control actually does any grouping or sorting the user may have attempted on the grid.
0
Sebastian
Telerik team
answered on 20 Apr 2010, 02:59 PM
Hello Bill,

The sample from the code library thread should not affect the sorting, paging, filtering, etc. capabilities of the grid. Can you please verify that you are using advanced binding with NeedDataSource event handling or assign a data source control for your grid?

If the issue seems to be elsewhere, please post the aspx/code-behind of your page in this forum thread (using the "Format Code Block" dialog). We will review it and will advice you further.

Kind regards,
Sebastian
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Bill
Top achievements
Rank 2
answered on 20 Apr 2010, 08:36 PM
using System; 
using System.Collections.Generic; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using Telerik.Web.UI; 
using System.Data; 
 
public partial class GroupEmailSearch : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e) 
    { 
 
    } 
    protected void rgGroupEmail_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        lblEmailCount.Text = rgGroupEmail.SelectedItems.Count.ToString(); 
    } 
    protected void btnSend_Click(object sender, EventArgs e) 
    { 
 
    } 
 

        <script type="text/javascript"
            function CancelNonInputSelect(sender, args) { 
 
                var e = args.get_domEvent(); 
                //IE - srcElement, Others - target   
                var targetElement = e.srcElement || e.target; 
 
 
                //this condition is needed if multi row selection is enabled for the grid   
                if (typeof (targetElement) != "undefined") { 
                    //is the clicked element an input checkbox? <input type="checkbox"...>   
                    if (targetElement.tagName.toLowerCase() != "input" && 
                                    (!targetElement.type || targetElement.type.toLowerCase() != "checkbox"))// && currentClickEvent)   
                    { 
 
                        //cancel the event   
                        args.set_cancel(true); 
                    } 
                } 
                else 
                    args.set_cancel(true); 
            }   
        </script> 
 
0
Bill
Top achievements
Rank 2
answered on 20 Apr 2010, 08:37 PM
        <asp:ObjectDataSource ID="odsGroupEmail" runat="server" OldValuesParameterFormatString="original_{0}" 
            SelectMethod="getEvalList" TypeName="LBNL.ITIS.EHS.ERGO.DB.GroupEmail"
            <SelectParameters> 
                <asp:SessionParameter Name="evalReasonList" SessionField="evalreasonlist" Type="String" /> 
                <asp:SessionParameter Name="evalExposureList" SessionField="evalexposurelist" Type="String" /> 
                <asp:SessionParameter Name="Division" SessionField="division" Type="String" /> 
                <asp:SessionParameter Name="evalRuleName" SessionField="evalrulename" Type="String" /> 
                <asp:SessionParameter Name="FromDate" SessionField="fromdate" Type="String" /> 
                <asp:SessionParameter Name="ToDate" SessionField="todate" Type="String" /> 
            </SelectParameters> 
        </asp:ObjectDataSource> 
        <table width="100%" border="0" cellpadding="3"
            <tr> 
                <td class="style1"
                    <style="font-family: Arial">Choose the employees to send email to:</a> 
                </td> 
                <td class="style1" align="right"
                    <style="font-family: Arial">Choose the email message to send:</a> 
                </td> 
                <td align="left" class="style3"
                    <telerik:RadComboBox ID="rcbEmailID" runat="server" DataSourceID="" DataTextField="SUBJECTLINE" 
                        DataValueField="IDN"
                    </telerik:RadComboBox> 
                </td> 
                <td align="left" valign="top"
                    <asp:Button ID="btnSend" runat="server" Text="Send Email"  
                        onclick="btnSend_Click" /> 
                </td> 
            </tr> 
        </table> 
        <telerik:RadGrid ID="rgGroupEmail" runat="server" AllowFilteringByColumn="True" AllowSorting="True" 
            AutoGenerateColumns="False" DataSourceID="odsGroupEmail" GridLines="None" Height="600px" 
             AllowMultiRowSelection="True" Width="1200px" ShowGroupPanel="True" OnSelectedIndexChanged="rgGroupEmail_SelectedIndexChanged"
            <HeaderContextMenu EnableAutoScroll="True"
            </HeaderContextMenu> 
            <MasterTableView AllowMultiColumnSorting="true" DataKeyNames="ERGO_ID" AllowFilteringByColumn="False"
                <Columns> 
                    <telerik:GridClientSelectColumn ButtonType="PushButton" HeaderText="Send Email"
                        <HeaderStyle Width="45px" /> 
                    </telerik:GridClientSelectColumn> 
                    <telerik:GridBoundColumn DataField="ERGO_ID" DataType="System.Decimal" Visible="false" 
                        HeaderText="ERGO_ID" SortExpression="ERGO_ID" UniqueName="ERGO_ID"
                        <HeaderStyle Width="125px" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="SUBJECTS_NAME" HeaderText="Subject's Name" SortExpression="SUBJECTS_NAME" 
                        UniqueName="SUBJECTS_NAME"
                        <HeaderStyle Width="125px" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="subjects_supervisor" HeaderText="Supervisor" 
                        SortExpression="subjects_supervisor" UniqueName="subjects_supervisor"
                        <HeaderStyle Width="125px" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="ERGO_EVALUATOR" HeaderText="Evaluator" UniqueName="column1"
                        <HeaderStyle Width="125px" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="discomfort_Prevent" HeaderText="Evaluation Reason" 
                        SortExpression="discomfort_Prevent" UniqueName="discomfort_Prevent"
                        <HeaderStyle Width="75px" /> 
                        <ItemStyle HorizontalAlign="Center" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EVAL_REQUEST_DATE" DataFormatString="{0:MM/dd/yyyy}" 
                        DataType="System.DateTime" HeaderText="Evaluation Request Date" ReadOnly="True" 
                        SortExpression="EVAL_REQUEST_DATE" UniqueName="EVAL_REQUEST_DATE"
                        <HeaderStyle Width="80px" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="EVAL_DATE" DataFormatString="{0:MM/dd/yyyy}" 
                        DataType="System.DateTime" HeaderText="Evaluation Date" ReadOnly="True" SortExpression="EVAL_DATE" 
                        UniqueName="EVAL_DATE"
                        <HeaderStyle Width="80px" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="subjects_division" HeaderText="Division" ReadOnly="true" 
                        SortExpression="subjects_division" UniqueName="subjects_division"
                        <HeaderStyle Width="200px" /> 
                        <ItemStyle Wrap="False" /> 
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="ergo_exposure" DefaultInsertValue="" HeaderText="Exposures" 
                        ReadOnly="true" SortExpression="ergo_exposure" UniqueName="ergo_exposure" ItemStyle-Wrap="true"
                        <HeaderStyle Width="350px" /> 
                        <ItemStyle Wrap="True" /> 
                    </telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
            <ClientSettings AllowDragToGroup="True" EnablePostBackOnRowClick="True"
                <Selecting AllowRowSelect="True" /> 
                <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
                <ClientEvents OnRowSelecting="CancelNonInputSelect" OnRowDeselecting="CancelNonInputSelect" /> 
            </ClientSettings> 
        </telerik:RadGrid> 
    </div> 
    <telerik:RadAjaxManager runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="btnSend"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="rgGroupEmail"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="lblEmailCount" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 

0
Sebastian
Telerik team
answered on 21 Apr 2010, 11:51 AM
Hello Bill,

From the code snippets you provided I see that you specified several SelectParameters for the ObjectDataSource instance that feeds the grid with data. Can you please check whether these parameters are set properly or influence the sorting/grouping capabilities of the grid (you may temporary disable them to test that)?

Furthermore, verify tha you set the OverrideDataSourceControlSorting property of the MasterTableView to true and consider migrating to the latest release 2010.1.415 of the suite.

Best regards,
Sebastian
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Bill
Top achievements
Rank 2
answered on 21 Apr 2010, 06:57 PM
Currently using 2010.1.309.35 - I will upgrade to 415

The parameters from the session are all empty at the moment -  The code on the search page sets them to null.
The SQL generated in the stored proc is essentially "Select * from vw_..."

The behavior I see is that when I click on a header, or drag a header to the group area, nothing happens until I click the "send email" button outside the grid.  Then the sort or grouping happens during the postback.  When I click on the column header the status line reads javascript: _doPostBack("rgGroupEmail...    but it is apparently not executed.

Bill
0
Sebastian
Telerik team
answered on 22 Apr 2010, 09:38 AM
Hello Bill,

Does adding an additional RadAjaxManager setting which specifies the grid as both initiator and updated control eliminates the abnormality? Namely:

<telerik:RadAjaxManager runat="server">  
       <AjaxSettings>  
           <telerik:AjaxSetting AjaxControlID="btnSend">  
               <UpdatedControls>  
                   <telerik:AjaxUpdatedControl ControlID="RadGrid1" />  
               </UpdatedControls>  
           </telerik:AjaxSetting
           <telerik:AjaxSetting AjaxControlID="RadGrid1">  
               <UpdatedControls>  
                   <telerik:AjaxUpdatedControl ControlID="RadGrid1" />  
               </UpdatedControls>  
           </telerik:AjaxSetting>  
           <telerik:AjaxSetting AjaxControlID="rgGroupEmail">  
               <UpdatedControls>  
                   <telerik:AjaxUpdatedControl ControlID="lblEmailCount" />  
               </UpdatedControls>  
           </telerik:AjaxSetting>  
       </AjaxSettings>  
   </telerik:RadAjaxManager>  

I suspect that the grid does not get refreshed as expected when you trigger request to the server on sorting or grouping operation.

Best regards,
Sebastian
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Naresh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Naresh
Top achievements
Rank 1
Bill
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or