radgrid client check box column check programmatically

2 posts, 0 answers
  1. shervinrv
    shervinrv avatar
    10 posts
    Member since:
    May 2007

    Posted 03 Oct 2014 Link to this post

    excuse me if my english is not well
    i have a radgrid with clientcheckbox column.
    i want check or uncheck each row in code behinde when page load.
    if in sql query column_active=0 then uncheck and if column_active=1 check the checkbox for each row
    how can i do this ?
    thank you
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 05 Oct 2014 in reply to shervinrv Link to this post


    Please try with the below code snippet.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
        <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnPreRender="RadGrid1_PreRender" AllowMultiRowSelection="true">
                <MasterTableView AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1">
                        <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column" HeaderText="Id" ReadOnly="True" SortExpression="Id" UniqueName="Id">
                                <ModelErrorMessage Text="" />
                        <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name column" HeaderText="Name" SortExpression="Name" UniqueName="Name">
                                <ModelErrorMessage Text="" />
                    <Selecting AllowRowSelect="true" />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [Id], [Name] FROM [Employee]"></asp:SqlDataSource>

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI;
    using System.Web.Services;
    using System.Collections.Generic;
    public partial class Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        protected void RadGrid1_PreRender(object sender, EventArgs e)
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
                if (item["ID"].Text == "1")
                    item.Selected = true;

    I have also attached screenshot for reference.

    Let me know if any concern.

    Jayesh Goyani
  3. DevCraft R3 2016 release webinar banner
Back to Top