Control Panel
Forum
Hosting Help
ASP.NET 3.5 & SQL 2008 Web Hosting
Resources
Login
Members
Shared Hosting
|
New Features
|
Advertise
|
Tutorials
|
Silverlight Tutorials
|
Product Reviews in India
|
Free aptitude test questions
|
TATA Nano Car reviews
Total
members
:
88776
Average new registrations per day (in last 7 days):
89
New Registration:
Open
Register Now
Home
»
Questions & Answers
»
How to assign drop downlist datasource dynamically?
How to assign drop downlist datasource dynamically?
6/10/2008
Author:
Suvendu Swain
Aptech Softwares
Hi,
I have 20 drop downlist in my page,
Named as :
DropdownList1
DropdownList2
DropdownList3
- - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - - -
DropdownList20
and I have to assign the same array to all the dropdowns, so instead of assigning manually to all the drop downs I want to use for loop.
like
for(int i=1;i<=20;i++)
{
eval("DropdownList"+i).DataSource=options;
eval("DropdownList"+i).Databind();
}
But by using eval this not possible and I am unable to use the typecasting too. can any one please help regarding this.
Thanks and Regards,
Subhendu Swain
Answers .............
Author:
Suvendu Swain
Aptech Softwares
Posted Date: 6/11/2008
HelpPlz
Author:
Rod Tidwell
Posted Date: 6/21/2008
http://aspspider.info/antartica
Antartica
Hi,
You can create an array of dropdownlists or a List<DropDownList> that you populate with all your dropdownlists. Then you iterate through that list (thanks to "foreach") and do whatever you want to do.
Author:
Stephen Debreczeny
Posted Date: 7/2/2008
you can use in Page Load
"dropdownlistid.datasource = datasourcecontrolid
dropdownlistid.databind()"
Author:
Jean-Francois Blouin
Posted Date: 9/24/2008
http://aspspider.net/JFBlouin
House for rent
Your DropdownList controls also seem to be ID'ed DropdownList1, DropdownList2 etc... so in the for loop, you can do:
for(int i=1;i<=20;i++)
{
Page.FindControl("DropdownList"+i).DataSource=options;
Page.FindControl("DropdownList"+i).Databind();
}
Jeff
Author:
Mani
Student
Posted Date: 9/25/2008
http://aspspider.info/Manis
HEC Scholarship Programme
for(int i=1;i<=20;i++)
{
DropdownList+i.DataSource= objDatatable;
DropdownList+i.DataTextField = "TextToBeDisplayed";
DropdownList+i.DataValueField="ValueToUsedBehindTheScene";
DropdownList+i.Databind();
}
Author:
Rod Tidwell
Posted Date: 9/28/2008
http://aspspider.info/antartica
Antartica
Mani... I think you should practice more lol. What you write is nonsense, sorry.
Author:
Naveen Sharma
Posted Date: 9/28/2008
Try something like this, you may want to start another for loop inside the for each loop
Private Sub binddd()
dim i as integer=1
For Each ocontrol As Control In Page.Controls
If ocontrol.ID = "DropdownList" + i Then
Dim dd As DropDownList
dd = CType(ocontrol, DropDownList)
dd.DataSource = Options'--your array
dd.DataBind()
i+=1
End If
Next
End Sub
You must
login
to post answer for this question.
Partners
Privacy Policy
Terms of use
Contact Us
SpiderWorks Technologies.
All Rights Reserved.