RadTreeView doesn't retrievechecked nodes

2 posts, 0 answers
  1. Babak
    Babak avatar
    12 posts
    Member since:
    Jan 2012

    Posted 14 Jan 2014 Link to this post

    Hi , I'm using radtreeview width checkbox="true" style .
    in button click I want to retrievechecked Items .
    I try to do this is 2 ways, but both have zero item counts . please check my code
    <asp:Button ID="Save" runat="server" Font-Names="Tahoma" Text="Save" OnClick="Save_Click" CssClass="savebutton"></asp:Button>
                          </div>
                          <telerik:RadTreeView ID="RadTreeView1" runat="server" DataTextField="SecNameFr" DataValueField="AccessId" DataFieldID="SecId" CheckBoxes="true" DataFieldParentID="SecIdRef" CheckChildNodes="true" Font-Names="tahoma" RenderMode="Classic" Skin="Office2010Blue">
                              <DataBindings>
                                  <telerik:RadTreeNodeBinding Checkable="true" CheckedField="HasAccess" />
                              </DataBindings>
                          </telerik:RadTreeView>
    protected void Save_Click(object sender, EventArgs e)
           {
               List<RadTreeNode> dss = RadTreeView1.CheckedNodes.ToList();
     
               Dictionary<int, bool> accessIdDic = new Dictionary<int, bool>();
               foreach (RadTreeNode item in RadTreeView1.Nodes)
               {
                   if (item.Checked)
                       accessIdDic.Add(Convert.ToInt32(item.Value), item.Checked);
               }
              
           }
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jan 2014 Link to this post

    Hi,

    Please have a look into the following code snippet which works fine at my end.

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server" DataTextField="text" DataValueField="text"
        DataFieldID="id" CheckBoxes="true" DataFieldParentID="parentid" CheckChildNodes="true"
        Font-Names="tahoma" RenderMode="Classic" Skin="Office2010Blue" DataSourceID="SqlDataSource1">
        <DataBindings>
            <telerik:RadTreeNodeBinding Checkable="true" CheckedField="status" />
        </DataBindings>
    </telerik:RadTreeView>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Save" OnClick="RadButton1_Click">
    </telerik:RadButton>

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        string[] array = new string[50];
        int i = 0;
        foreach (RadTreeNode item in RadTreeView1.CheckedNodes)
        {
            array[i] = item.Text;
            i++;
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top