Ticket T572267
Visible to All Users

ASPxGridView - The CheckedChanged event does not fire when ASPxCheckBox is placed inside DataItemTemplate

created 7 years ago (modified 7 years ago)

I am having ASPxGridview with checkbox column.,

ASPx
<dx:ASPxGridView ID="gridChecklist" runat="server" ClientInstanceName="gridChkLst" OnCustomColumnDisplayText="grid_CustomColumnDisplayText" AutoGenerateColumns="false" OnCustomCallback="gridChecklist_CustomCallback" KeyFieldName="ChecklistID"> <Settings AutoFilterCondition="Contains" ShowHeaderFilterButton="true" ShowFilterRow="True" /> <SettingsDataSecurity AllowDelete="False" AllowEdit="False" AllowInsert="False" /> <SettingsSearchPanel Visible="True" /> <Columns> <dx:GridViewDataTextColumn FieldName="ChecklistID" Visible="false" Width="10" Name="colId" VisibleIndex="1"></dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="AuditType" VisibleIndex="2" Width="200" Caption="Audit Type" Name="colAudTp"></dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="ChecklistType" VisibleIndex="3" Width="200" Caption="Checklist Type" Name="colChkTp"></dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="ChecklistName" VisibleIndex="4" Width="400" Caption="Checklist Name" Name="colChkNm"></dx:GridViewDataTextColumn> <<strong>dx:GridViewDataCheckColumn FieldName="StatusID" Caption="Active/Inactive" VisibleIndex="5" Name="colStat"> <DataItemTemplate> <dx:ASPxCheckBox ID="cbStatus" runat="server" Value='<%# Bind("StatusID") %>' ValueType="System.Int64" ValueChecked="1" ValueUnchecked="0" OnCheckedChanged="cbStatus_checkedChanged"> </dx:ASPxCheckBox> </DataItemTemplate> </dx:GridViewDataCheckColumn></strong> <dx:GridViewCommandColumn ShowNewButton="true" ShowEditButton="true" VisibleIndex="9" ButtonRenderMode="Image" Caption="Edit" Name="col_Edit"> <CustomButtons> <dx:GridViewCommandColumnCustomButton ID="colEdit"> <Image ToolTip="Edit" Url="~/Images/edit_icon.png"></Image> </dx:GridViewCommandColumnCustomButton> </CustomButtons> </dx:GridViewCommandColumn> <dx:GridViewCommandColumn ShowNewButton="true" ShowEditButton="true" VisibleIndex="10" ButtonRenderMode="Image" Caption="Delete" Name="col_Del"> <CustomButtons> <dx:GridViewCommandColumnCustomButton ID="colDel"> <Image ToolTip="Delete" Url="~/Images/close_icon.png"></Image> </dx:GridViewCommandColumnCustomButton> </CustomButtons> </dx:GridViewCommandColumn> <dx:GridViewCommandColumn ShowNewButton="true" ShowEditButton="true" VisibleIndex="11" ButtonRenderMode="Image" Caption="Copy" Name="col_Copy"> <CustomButtons> <dx:GridViewCommandColumnCustomButton ID="colCopy"> <Image ToolTip="Copy" Url="~/Images/Copy_Theme.png"></Image> </dx:GridViewCommandColumnCustomButton> </CustomButtons> </dx:GridViewCommandColumn> <dx:GridViewDataTextColumn Caption="S/N" UnboundType="Integer" VisibleIndex="0" Name="SN"> </dx:GridViewDataTextColumn> </Columns> <ClientSideEvents CustomButtonClick="OnCustomButtonClick" /> </dx:ASPxGridView>

My .cs page,

C#
protected void cbStatus_checkedChanged(object sender, EventArgs e) { ASPxCheckBox cbChkBox = sender as ASPxCheckBox; GridViewDataItemTemplateContainer container = cbChkBox.NamingContainer as GridViewDataItemTemplateContainer; String chkLstid; chkLstid = container.KeyValue.ToString(); }

I am binding gridview like,

gridChecklist.DataSource = SessionChecklistListing;   //data table
 gridChecklist.DataBind();

What's wrong in this?

Answers approved by DevExpress Support

created 7 years ago (modified 7 years ago)

Hello Harshada,

The issue is related to the fact that it is necessary to set the AutoPostBack property to true to allow our CheckBox to trigger a postback request:

ASPx
<dx:ASPxCheckBox AutoPostBack="true"> </dx:ASPxCheckBox>

Let me know if you have further questions.

    Comments (3)
      C#
      It's contradicting to page_load()

      In page load i am binding the grid.

      gridChecklist.DataSource = SessionChecklistListing;   //data table
       gridChecklist.DataBind();

      It do post back now and checkbox event fires but again due to page_load it checks the checkbox.
      If I write,

      C#
      if (!IsPostBack) { BindChecklist(); }

      Then after changing page, grid won't load.

      So If I write in OnInit()

      C#
      protected override void OnInit(EventArgs e) { base.OnInit(e); BindChecklist(); }

      Will it be a problem?
      Now it's working but I am afraid whether it's correct logic or not?

      Lanette (DevExpress Support) 7 years ago

        Hello,

        The problem may occur if you're setting checkbox values in the Page_Load event handler because this event fires after restoring these checkbox values from post data and as a result, your custom code checks these checkboxes and resets the selection made by a user. As I understand from your previous comment, the issue is resolved when you're setting these checkbox values in the Page_Init event handler. In general, I don't see any potential problems in this approach. Let us know if you have further difficulties with this scenario and provide us with a sample runnable project where we can reproduce them.

          OK Noted. Thanks.
          Will let you know if any problem comes.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.