|
-
Jul 14th, 2008, 11:37 AM
#1
[RESOLVED] [02/03] copy from one dropdownlist to another
I want to copy data from one dropdown list data to another one,Is it possible to do without loop?
This is how i am doing currently
Code:
ddlSerchIn.Items.Insert(0, "Data1")
ddlSerchIn.Items(0).Value = "Data1"
ddlSerchIn.Items.Insert(1, "Data2")
ddlSerchIn.Items(1).Value = "Data2"
Dim lstItems As ListItem
For Each lstItems In ddlSerchIn.Items
ddlAdvSearch1.Items.Add(lstItems)
Next
__________________
Rate the posts that helped you 
-
Jul 14th, 2008, 12:12 PM
#2
Re: [02/03] copy from one dropdownlist to another
Check .Items.CopyTo function of DDL class. It returns an array of ListItem.
VB Code:
Dim lstItems As New ListItem[ddlSerchIn.Items.Count] ddlSerchIn.Items.CopyTo(lstItems, 0) ddlAdvSearch1.DataSource = lstItems ddlAdvSearch1.DataBind()
Just wrote from top of my head.
Edit: changing language from C# to VB
-
Jul 14th, 2008, 12:16 PM
#3
Re: [02/03] copy from one dropdownlist to another
One more point to be made:
If the first DDL is bound to a datasource, you can just retrieve its datasource, pass it to the other one and call DataBind() of second DDL.
-
Jul 14th, 2008, 12:39 PM
#4
Re: [02/03] copy from one dropdownlist to another
Thanks for the code snnipet,here is vb ver of same...
Code:
Dim lstItems As ListItem() = New ListItem(ddlSerchIn.Items.Count -1){}
ddlSerchIn.Items.CopyTo(lstItems, 0)
ddlAdvSearch1.AddRange(lstItems )
__________________
Rate the posts that helped you 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|