CheckedChanged event not firing in dynamically created GridCheckBoxColumn

5 posts, 0 answers
  1. Rajesh Duraisamy
    Rajesh Duraisamy avatar
    9 posts
    Member since:
    Jul 2012

    Posted 26 May Link to this post

    Hi,

    I am programatically creating few GridCheckBoxColumn in the grid and in the ItemCreated event of the grid i am adding the CheckedChanged event but the CheckedChanged event is not getting fired.

    Can you please help me to fix this.

    ASPX:

    <ic:SettingGrid runat="server" ID="grRemainderMappings" DisableAddNew="true" OnItemCreated="grRemainderMapping_ItemCreated">
                                    <MasterTableView>   
                                        <Columns>
                                                <telerik:GridBoundColumn UniqueName="AppointmentReasonId" DataField="AppointmentReasonId" HeaderText="AppointmentReasonId" Display="false"/>
                                                <telerik:GridBoundColumn UniqueName="ReasonCode" DataField="ReasonCode" HeaderText="Reason Code"/>
                                                <telerik:GridBoundColumn UniqueName="Description" DataField="Description" HeaderText="Description"/>
                                            </Columns>                                  
                                            <NoRecordsTemplate>
                                                    <div class="ListGridNoRecords">There are no selected templates to display</div>
                                            </NoRecordsTemplate>
                                        </MasterTableView>
                                    </ic:SettingGrid>

    C#:

    protected void grRemainderMapping_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem dItem = e.Item as GridDataItem;
                    for (int i = 3; i < dtMapping.Columns.Count; i++)
                    {
                        CheckBox chkbox = (CheckBox)dItem[dtMapping.Columns[i].ColumnName].Controls[0];
                        chkbox.ToolTip = "Select this template";
                        chkbox.Enabled = true;
                        chkbox.AutoPostBack = true;
                        chkbox.CheckedChanged += new EventHandler(cbxReader_CheckedChanged);
                    }
                }           
            }
     void cbxReader_CheckedChanged(object sender, EventArgs e)
            {
                loadSelectedTemplates();
            }
    private DataTable loadMappingGrid()
            {
                try
                {
                    dtMapping = Proxy.DmAppointments.GetPracticeAppointmentReminderTemplatesMapping(this.selectedPracticeId);
                    for (int j = 3; j < dtMapping.Columns.Count; j++)
                    {
                        ChangeColumnDataType(dtMapping, dtMapping.Columns[j].ColumnName, typeof(bool));
                    }               
                    int count = this.grRemainderMappings.MasterTableView.Columns.Count;
     
                    for (int i = 3; i < count; i++)
                    {
                        this.grRemainderMappings.MasterTableView.Columns.RemoveAt(3);
                    }
                    for (int j = 3; j < dtMapping.Columns.Count; j++)
                    {
                         if (dtMapping.Columns[j].ColumnName != "AppointmentReasonId" && dtMapping.Columns[j].ColumnName != "ReasonCode" && dtMapping.Columns[j].ColumnName != "Description")
                        {
                            GridCheckBoxColumn checkBoxColumn = new GridCheckBoxColumn();
                            this.grRemainderMappings.MasterTableView.Columns.Add(checkBoxColumn);
                            checkBoxColumn.UniqueName = dtMapping.Columns[j].ColumnName;
                            checkBoxColumn.DataField = dtMapping.Columns[j].ColumnName;         
                            DataRow[] dr = dtTemplate.Select("TemplateId = "+dtMapping.Columns[j].ColumnName +"");
                            if (dr.Length != 0)
                            {
                                string templateName = (string)dr[0][1];
                                checkBoxColumn.HeaderText = templateName; 
                            }                      
                            checkBoxColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                        }
                    }
                }
                catch (Exception ex)
                {
                 this.errorMessage("Error while loading templates for practice", ex.Message, ex.StackTrace);
                }
                return dtMapping;
            }
     
     protected void Page_Load(object sender, EventArgs e)
            {
                try
                {              
                    if (!this.IsPostBack)
                    {                   
                        grRemainderTemplates.DataSource = loadTemplatesGrid();
                        grRemainderTemplates.DataBind();
                        grRemainderMappings.DataSource = loadMappingGrid();
                        grRemainderMappings.DataBind();
                    }
                }
                catch (Exception ex)
                {
                     
                }
            }

    Thanks in advance.

    Regards,

    Rajesh.

  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 31 May Link to this post

    Hi,

    Try attaching the event using the RadGrid ItemDataBound event and see how it goes.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rajesh Duraisamy
    Rajesh Duraisamy avatar
    9 posts
    Member since:
    Jul 2012

    Posted 31 May in reply to Maria Ilieva Link to this post

    Hi,

    I have already tried that and it is also not working :(.

    Regards,

    Rajesh D

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 02 Jun Link to this post

    Hi,

    Can you please check if any javascript error appear on the page when you are using the chekbox control? Also if any Ajax settings exists on the page, remove them and see how it goes.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  6. Rajesh Duraisamy
    Rajesh Duraisamy avatar
    9 posts
    Member since:
    Jul 2012

    Posted 26 Jul Link to this post

    Hi Maria,

    It started working after setting enableviewstate=false in the grid.

    Thankyou.

    Regards,

    Rajesh D

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017