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

RadTreeView doesn't retrievechecked nodes

1 Answer 48 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Babak
Top achievements
Rank 1
Babak asked on 14 Jan 2014, 09:15 AM
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);
           }
          
       }

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Jan 2014, 11:33 AM
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.
Tags
TreeView
Asked by
Babak
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or