Loop through RadGrid and read Check Boxes when not in edit mode

by ebarcza 10/10/2017 8:17:00 AM

Step 1 - create a GridTemplate Column with a checkbox

 <telerik:GridTemplateColumn UniqueName="colCheckDelete" HeaderText="Delete">
                    <ItemTemplate>
                        <asp:CheckBox ID="chkDelete" runat="server" />
                   </ItemTemplate>

 </telerik:GridTemplateColumn>

Step 2 - The codebehind loop

foreach (GridDataItem item in rgDeals.MasterTableView.Items)
        {
            CheckBox chkDelete = (CheckBox)item["colCheckDelete"].FindControl("chkDelete");
            if(chkDelete.Checked)
            {
                //Delete the deal
                try
                {
                    int dealID = Convert.ToInt32(item.GetDataKeyValue("DealID"));
                    string sql = "Delete stuff where dealID = " + dealID;
                    int rslt = Utility.ExecuteNonQuerySQL(sql);
                }
                catch (IndexOutOfRangeException ex)
                {
                    //do nothing
                }
                catch (Exception ex)
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alert", "CreateMasterAlert('alert alert-danger', '" + "One or More deletes failed" + "');", true);
                }
            }
        }
        rgDeals.Rebind();
        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alert", "CreateMasterAlert('alert alert-success', '" + "Delete Operation completed" + "');", true);

Tags:

.NET | SQL SERVER | Telerik

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  October 2018  >>
MoTuWeThFrSaSu
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Recent comments

Tags

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2018

Sign in