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

CheckedChanged event not firing in dynamically created GridCheckBoxColumn

4 Answers 711 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rajesh
Top achievements
Rank 1
rajesh asked on 26 May 2016, 11:52 AM

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.

4 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 31 May 2016, 11:37 AM
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.
0
rajesh
Top achievements
Rank 1
answered on 31 May 2016, 12:54 PM

Hi,

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

Regards,

Rajesh D

0
Maria Ilieva
Telerik team
answered on 03 Jun 2016, 09:40 AM
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.
0
rajesh
Top achievements
Rank 1
answered on 26 Jul 2016, 12:37 PM

Hi Maria,

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

Thankyou.

Regards,

Rajesh D

Tags
Grid
Asked by
rajesh
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
rajesh
Top achievements
Rank 1
Share this question
or