This is a migrated thread and some comments may be shown as answers.

radgrid client check box column check programmatically

1 Answer 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shervinrv
Top achievements
Rank 1
shervinrv asked on 03 Oct 2014, 02:30 PM
hello.
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

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Oct 2014, 12:29 PM
Hi,

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">
    <title></title>
    <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">
            
        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnPreRender="RadGrid1_PreRender" AllowMultiRowSelection="true">
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1">
                <Columns>
                    <telerik:GridClientSelectColumn></telerik:GridClientSelectColumn>
                    <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" FilterControlAltText="Filter Id column" HeaderText="Id" ReadOnly="True" SortExpression="Id" UniqueName="Id">
                        <ColumnValidationSettings>
                            <ModelErrorMessage Text="" />
                        </ColumnValidationSettings>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name column" HeaderText="Name" SortExpression="Name" UniqueName="Name">
                        <ColumnValidationSettings>
                            <ModelErrorMessage Text="" />
                        </ColumnValidationSettings>
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings>
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [Id], [Name] FROM [Employee]"></asp:SqlDataSource>
    </form>
</body>
</html>


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.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
shervinrv
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or