1

I am using asp TreeView control. I want to get selected "checboxes" values at client side. How do I get selected values from TreeView?

0

3 Answers 3

2

Suppose your treeview has id treeviewid

$('#treeviewid input[type=checkbox]:checked').each(function(){
   alert($(this).val());    
});
Sign up to request clarification or add additional context in comments.

4 Comments

I am getting "On" as output. I want value of checkbox which is binding while creating treeview. tn.ChildNodes.Add(new TreeNode(Sector.SectorName, Sector.SectorId.ToString())); @
You can use attr to get the attributes e.g. you want to get attribute name, alert($(this).attr('name'));
adil-> I want SectorID , but when I see in source view I can't find it.
Check it might be given to some other html element, if you can find it in source then we can access it. If it is not source then it is impossible to get it.
1

I think you should use clientId

$('#<%=MyTreeView.ClientID%>').find(':checkbox:checked').each(function(){
   console.log($(this).val());    
});

1 Comment

Yes, but .find selector doesn't need "input" and should look like .find(':checkbox:checked').
1

I've used the following code to determine all the checked checkboxes:

$("input:checkbox").each(function () {
    if ($(this).is(':checked')) {
        //do something
    }
}

1 Comment

So simple, so nice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.