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

preventing rowclick event firing on checkbox seelction/deselection

6 Answers 261 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 03 Aug 2012, 01:33 PM
i have a grid with a checkbox on each row for users to select records for deletion.

however clicking on the row enables the user to edit that record.

checking or deselecting the checkbox is firing the rowclick and showing the edit popup, how do i prevent this happening ?

i dont want this rowclick to fire when the checkbox is ticked or unticked....

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Aug 2012, 07:00 AM
Hi Mark,

I tried the same scenario and I couldn't replicate the issue. Here is the sample code snippet I tried.

ASPX:
<telerik:RadGrid ID="rad" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" AutoGenerateEditColumn="true" onitemdatabound="rad_ItemDataBound">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn UniqueName="ProductID" DataField="ProductID"></telerik:GridBoundColumn>
            <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" HeaderText="selet">
                    <ItemTemplate>
                            <asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server"></asp:CheckBox>
                    </ItemTemplate>    
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnRowClick="OnRowClick" />
    </ClientSettings>
</telerik:RadGrid>

C#:
protected void ToggleRowSelection(object sender, EventArgs e)
{
    ((sender as CheckBox).NamingContainer as GridItem).Selected = (sender as CheckBox).Checked;
}

Javascript:
<script type="text/javascript">
    function OnRowClick(sender, eventArgs)
     {
        editedRow = eventArgs.get_itemIndexHierarchical();
        $find("<%= rad.MasterTableView.ClientID %>").editItem(editedRow);
    }
</script>

Please provide the code if it doesn't help.

Thanks,
Shinu.
0
Mark
Top achievements
Rank 1
answered on 06 Aug 2012, 07:59 AM
thanks,

well in my example the checkbox is added in the code behind as its dependant on the user role.

so im not sure what the checkbox id is that fires the checkchanged event...

also the rowclick is detected in the code behind... the update process involves populating the update form and launching this in a popup to the user... 

Me.pBlocks.VisibleOnPageLoad = True

for now i detect if checkbox selected in ItemCommand event and dont proceed with check fo rowclick but this stops the rowclick firing at all apart from de-selecting the checkbox which isnt the desired response... so seeking a way to keep these 2 events apart and not affecting each other....
If Master.MembershipUser.ReadOnlyAccess = False Then
                AddCheckBox(Me.uxBlocks)
End If
 
 
Public Sub AddCheckBox(ByRef grid As RadGrid)
        Dim gbc As New GridClientSelectColumn
        grid.Columns.Insert(0, gbc)
        gbc.HeaderText = "Select"
        gbc.UniqueName = "Select"
        gbc.CommandName = "Select"
        gbc.ItemStyle.HorizontalAlign = HorizontalAlign.Center
        gbc.HeaderStyle.Width = Unit.Pixel(70)
        gbc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
End Sub
 
 
Private Sub uxBlocks_ItemCommand(source As Object, e As GridCommandEventArgs) _
        Handles uxBlocks.ItemCommand
 
        Dim gItem As GridDataItem
 
        If e.CommandName = "RowClick" Then
 
        'do the update process

0
Mark
Top achievements
Rank 1
answered on 06 Aug 2012, 03:32 PM
i think i need to add the checkbox directly to the grid rather than in the code behind so i can access the oncheckedchanged event which should enable me to determine a checkbox click from a rowclick...

however i added the checkbox column as in your code but the checkbox doesnt appear in my grid...

heres my grid code...

<telerik:RadGrid ID="uxBlocks" runat="server"
            EnableViewState="true" AllowAutomaticDeletes="false"
                AutoGenerateColumns="False" AllowSorting="True"
                GridLines="None" Skin="Default" AllowPaging="True" Culture="(Default)" PageSize="20" AllowMultiRowSelection="true"
                Width="100%" Height="350px" AllowFilteringByColumn="true"
            EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" OnItemDataBound="uxBlocks_ItemDataBound"
            GroupingEnabled="false">
            <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true" >
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                <Selecting AllowRowSelect="True" EnableDragToSelectRows="false" />
            </ClientSettings>
            <MasterTableView IsFilterItemExpanded="false">
            <Columns>
                <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" HeaderText="Select" Visible="true">
                     <ItemTemplate>
                             <asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" Visible="True" AutoPostBack="True" runat="server"></asp:CheckBox>
                     </ItemTemplate>    
                </telerik:GridTemplateColumn>
                </Columns>
 
                <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" /> 
                              
            </MasterTableView>          
            <GroupingSettings CaseSensitive="False" />
        </telerik:RadGrid>

0
Shinu
Top achievements
Rank 2
answered on 07 Aug 2012, 06:15 AM
Hi Mark,

I tried your code and the checkboxes are showing. How are you adding other columns in the RadGrid? RadGrid does not support mixing declarative grid columns with grid columns added dynamically at runtime.

Thanks,
Shinu.
0
Mark
Top achievements
Rank 1
answered on 07 Aug 2012, 07:41 AM
ok thats the reason then as the columns are being added in the code behind...

so is there a way to solve this issue with the checkbox being added in the code behind also as i cant add it to the grid directly ?

can i get the checkbox id this way?

0
Mark
Top achievements
Rank 1
answered on 07 Aug 2012, 03:52 PM
ok i have found a workaround by adding a client event to the rad grid which then uses javascript to detect if its a rowclick or a checkbox click...

i then set a hidden field value depending on which of these has occurred and check this in the itemcommand event in code behind.....
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Share this question
or