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.