How to check and uncheck the Telerik component Checkbox?

Asked

Viewed 79 times

1

I searched the website of Telerik and not found where it shows how to do to enable the Checkbox (mark and unmark) of this component ?
'Cause I’m gonna need to update the profile by sending it to the database True or False;
inserir a descrição da imagem aqui

HTML:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebTreelist._Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

</asp:Content>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">



    <div class="col-md-12">
        <div id="divErro" runat="server" visible="false">
            <div class="col-sm-12">
                <div class="alert alert-info" role="alert">
                    <asp:Label runat="server" ID="lblAviso"></asp:Label></div>
            </div>
        </div>      

    </div>

    <div class="col-md-12">

   <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadTreeList1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadTreeList1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="ConfiguratorPanel1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadTreeList1"></telerik:AjaxUpdatedControl>
                    <telerik:AjaxUpdatedControl ControlID="ConfiguratorPanel1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadTreeList RenderMode="Lightweight" ID="RadTreeList1" runat="server" OnNeedDataSource="RadTreeList1_NeedDataSource"
        ParentDataKeyNames="ParentID" DataKeyNames="ID" AllowPaging="true"
        AutoGenerateColumns="false" AllowSorting="true" ExpandCollapseMode="Client">
        <ClientSettings>
            <Selecting AllowItemSelection="true" />
        </ClientSettings>
        <Columns>

            <telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="Category ID" Visible="false">
            </telerik:TreeListBoundColumn>
            <telerik:TreeListTemplateColumn DataField="Perfil" UniqueName="Perfil"
                HeaderText="Perfil">
                <ItemTemplate>
                   <%# Eval("Perfil")%>
                </ItemTemplate>
            </telerik:TreeListTemplateColumn>

            <telerik:TreeListCheckBoxColumn DataField="AcaoG" UniqueName="AcaoG" HeaderText="Gravar">
            </telerik:TreeListCheckBoxColumn>

            <telerik:TreeListCheckBoxColumn DataField="AcaoD" UniqueName="AcaoD" HeaderText="Deletar">
            </telerik:TreeListCheckBoxColumn>

            <telerik:TreeListCheckBoxColumn DataField="AcaoE" UniqueName="AcaoE" HeaderText="Editar">
            </telerik:TreeListCheckBoxColumn>
            <telerik:TreeListCheckBoxColumn DataField="AcaoV" UniqueName="AcaoV" HeaderText="Visualizar">
            </telerik:TreeListCheckBoxColumn>

        </Columns>
    </telerik:RadTreeList>



        </div>
</asp:Content>

CODE:

using System;
using System.Collections.Generic;
using System.Web.UI;
using Telerik.Web.UI;
using Telerik.Web.Design;
using WebTreelist.Business;
using WebTreelist.Models;

namespace WebTreelist
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    RadTreeList1.ExpandedIndexes.Add(new TreeListHierarchyIndex { LevelIndex = 0, NestedLevel = 0 });
                    RadTreeList1.ExpandedIndexes.Add(new TreeListHierarchyIndex { LevelIndex = 1, NestedLevel = 0 });
                    RadTreeList1.ExpandedIndexes.Add(new TreeListHierarchyIndex { LevelIndex = 2, NestedLevel = 0 });
                    RadTreeList1.ExpandedIndexes.Add(new TreeListHierarchyIndex { LevelIndex = 3, NestedLevel = 0 });
                }
            }
            catch (Exception ex)
            {
                this.lblAviso.Text = ex.Message;
            }
        }

        protected void RadTreeList1_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
        {
            RadTreeList1.DataSource = MyData.GetData();
        }       

    }

    public class MyData
    {
        public static List<MyItem> GetData()
        {
            List<MyItem> list = new List<MyItem>();
            list.Add(new MyItem("1", "Administrador", false, false, false, false, ""));
            list.Add(new MyItem("2", "Coordenador", false, false, false, false, ""));
            list.Add(new MyItem("3", "Operacional",  false, false, false, false, ""));

            list.Add(new MyItem("11", "Pesquisar Outages", false, false, false, false, "1"));
            list.Add(new MyItem("22", "Criar Nova Outages",  false, false, false, false, "1"));
            list.Add(new MyItem("33", "Pesquisar Grupos",  true, false, false, false, "1"));
            list.Add(new MyItem("44", "Criar novo Grupo de Outage",  true, false, false, false, "1"));
            list.Add(new MyItem("55", "Agenda de Outages",  false, false, false, false, "1"));
            list.Add(new MyItem("66", "Relatório de Outages",  false, false, false, false, "1"));
            list.Add(new MyItem("77", "Gerenciar Usuários", false, false, false, false, "1"));
            list.Add(new MyItem("88", "Perfil de usuário", true, false, false, false, "1"));

            list.Add(new MyItem("99", "Pesquisar Outages", true, false, false, false, "2"));
            list.Add(new MyItem("100", "Criar Nova Outages",  false, false, false, false, "2"));
            list.Add(new MyItem("110", "Pesquisar Grupos",  false, false, false, false, "2"));
            list.Add(new MyItem("120", "Criar novo Grupo de Outage",  false, false, false, false, "2"));
            list.Add(new MyItem("130", "Agenda de Outages",  false, false, false, false, "2"));
            list.Add(new MyItem("140", "Relatório de Outages", false, false, false, false, "2"));

            list.Add(new MyItem("150", "Pesquisar Outages", true, false, false, false, "3"));
            list.Add(new MyItem("160", "Criar Nova Outages", false, false, false, false, "3"));
            list.Add(new MyItem("170", "Pesquisar Grupos", false, false, false, false, "3"));

            return list;
        }
    }
    public class MyItem
    {
        public string ID { get; set; }
        public string Perfil { get; set; }
        public bool AcaoG { get; set; }
        public bool AcaoD { get; set; }
        public bool AcaoE { get; set; }
        public bool AcaoV { get; set; }

        public string ParentID { get; set; }
        public MyItem(string id, string productName,  bool acaoG, bool acaoD, bool acaoE, bool acaoV, string parentID)
        {
            ID = id;
            Perfil = productName;
            AcaoG = acaoG;
            AcaoD = acaoD;
            AcaoE = acaoE;
            AcaoV = acaoV;
            ParentID = parentID;
        }
    }
}
  • i don’t know much from Treelerik.. but make an attempt: add Allowmultiitemselection="true" in your <Telerik:Radtreelist>

1 answer

0


Hello, in your case it would be easier to use a RADGRID with a selector where you can use the Gridclientselectcolumn that would be more practical!

Example to see if the value was selected or not

for (int i = 0; i < Radgrid1.items.count; i++)
{
    if(Radgrid1.items.selected)
      {
         nesse metodo vem apenas os que você marco no grid
         podendo colocar aqui a query para inserir!
      }
}

grid link with Gridclientselectcolumn :https://demos.telerik.com/aspnet-ajax/grid/examples/columns-rows/columns/column-types/defaultcs.aspx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.