How to use dropdownlist in treeview (web controls)

K

Kevin

Hi all,

I got a problem about TreeView, I would like to create a
dropdownlist in treeview as a treenode. I've tried the
using following code

TreeView testTree = new TreeView();
TreeNode testNode = new TreeNode();
testNode.Text="<select size=\"1\" name=\"C5_7\" ><option
value=\"test\" selected>Basic</option><option
value=\"test22\">Basic1</option></select>";

the above code will show a dropdownlist in the treeview.

For now my problem is I was unable to get the value of
dropdownlist. Please note that I've try to use
HttpContext.Current.Request["C5_7"], but it doesn't work.
If I did't put dropdownlist in the treeview, but page. I
was able to get the value of dropdownlist by
HttpContext.Current.Request.["C5_7"].

Hope you can give me some suggestions about it. Any
suggestions will be Highly appreciated.

Kevin
 
A

Alvin Bruney

This is being done client-side so you will need to put the selected value
for the dropdown in either a hidden field or populate the request object
with it. It isn't being done for u automatically which is why you cannot
access it thru the request object.

--
Regards,
Alvin Bruney
Got DotNet? Get it here
http://home.networkip.net/dotnet/tidbits/default.htm
Kevin said:
Is there anyone can answer my question?
-----Original Message-----
Hi all,

I got a problem about TreeView, I would like to create a
dropdownlist in treeview as a treenode. I've tried the
using following code

TreeView testTree = new TreeView();
TreeNode testNode = new TreeNode();
testNode.Text="<select size=\"1\" name=\"C5_7\" ><option
value=\"test\" selected>Basic</option><option
value=\"test22\">Basic1</option></select>";

the above code will show a dropdownlist in the treeview.

For now my problem is I was unable to get the value of
dropdownlist. Please note that I've try to use
HttpContext.Current.Request["C5_7"], but it doesn't work.
If I did't put dropdownlist in the treeview, but page. I
was able to get the value of dropdownlist by
HttpContext.Current.Request.["C5_7"].

Hope you can give me some suggestions about it. Any
suggestions will be Highly appreciated.

Kevin
.
 
K

Kevin C

Hi Alvin,

At first, I am highly appreciated for your reply.
You told me that
" you will need to put the selected value
for the dropdown in either a hidden field or populate the request object
with it"
I am not so clear about above answer, can u please provide a few of
example code for me?

Thank you very much!

Kevin
 
A

Alvin Bruney

I was suggesting some clientside script to retrieve the selected value and
populate a hidden text box.
so if you had a textbox with it's visibility property set to false, then you
could assign the textbox1.text = dropdown.selecteditem. On your post back,
you can then check the textbox value to see if it contained anything. This
is the easier way, otherwise your dynamically added dropdown needs to have
viewstate enabled or added to the page's viewstate. I've actually done this
but the code is in source safe and i'm on holidays for a couple weeks. I'll
try to get it to you when i get back if you haven't figured out something by
then.

It will be a bit tricky to retrieve the control on the tree node but
basically you would have to find the
selected node and then find the control at the node casting it to a dropdown
list. at that point on the server side, the item selection would be empty
because the viewstate is not maintained for dynamic controls which is why
i'm suggesting you store the dropdown selection in a textbox in the first
place.
 
K

Kevin C

Hi Alvin,

Thanks very much for your suggestions and sorry for delayed. I will try
it myself. Anyway, I really hope you can send some of sample code to me
if you got free.

Thanks again.
Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,815
Messages
2,569,705
Members
45,494
Latest member
KandyFrank

Latest Threads

Top