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

<<  August 2018  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

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