I am created a application using Telerik:RadGrid.It performs insert, update, delete operations successfully. I have taken a checkbox and a Button in header of one column and all the rows of that column contain checkboxex. Whenever I select the checkboxed and click on the delete button it deletes the selected records from the grid. When i Select the Header checkbox , it will select all the records of the grid with in that page and by click on the delete button it deletes all the records from that page.
I want to delete all the records across the grid when ever i select the header checkbox and click the Delete button instead delete records page wise. Can anybody help me to solve this problem.
Here is my code used to delete records page wise.
<telerik:GridTemplateColumn UniqueName="TemplateColumn" ItemStyle-HorizontalAlign = "Center">
<HeaderStyle Font-Bold = "true" Font-Names = "Verdana" Width = "15%" CssClass = "GridButton"/>
<HeaderTemplate>
<asp:CheckBox id="headerChkbox" AutoPostBack="True" runat="server"
oncheckedchanged="headerChkbox_CheckedChanged"></asp:CheckBox>
<asp:Button ID = "btnDelete" runat = "server" Text = "Delete" BackColor = "#336699" CssClass = "GridButton" ForeColor = "White" onclick="btnDelete_Click"/>
</HeaderTemplate>
.cs:.
protected void headerChkbox_CheckedChanged(object sender, EventArgs e)
{
if ((sender as CheckBox).Checked)
{
foreach (GridDataItem dataItem in radSurgicalHistory.MasterTableView.Items)
{
(dataItem.FindControl(
"chkRowSelection") as CheckBox).Checked = true;
dataItem.Selected =
true;
}
}
else
{
foreach (GridDataItem dataItem in radSurgicalHistory.MasterTableView.Items)
{
(dataItem.FindControl(
"chkRowSelection") as CheckBox).Checked = false;
dataItem.Selected =
false;
}
}
}
protected void chkRowSelection_CheckedChanged(object sender, EventArgs e)
{
((sender
as CheckBox).Parent.Parent as GridItem).Selected = (sender as CheckBox).Checked;
}
try
{
if (radSurgicalHistory.MasterTableView.DataKeyNames.Length > 0)
{
string pkId = "";
string key = radSurgicalHistory.MasterTableView.DataKeyNames[0];
for (int i = 0; i < radSurgicalHistory.SelectedItems.Count; i++)
{
pkId = radSurgicalHistory.MasterTableView.DataKeyValues[radSurgicalHistory.SelectedItems[i].ItemIndex][key].ToString();
string delete = "Update M_SURGICAL_HISTORY SET ROW_STATUS = 0 where Pk_Surgical_History = " + pkId + "";
SqlHelper.ExecuteNonQuery(Utilities.GetConnectionString, CommandType.Text, delete);
}
radSurgicalHistory.Rebind();
}
}
catch (Exception ex)
{
radSurgicalHistory.Controls.Add(
new LiteralControl("Unable to delete Customers. Reason: " + ex.Message));
}