473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Dynamic DropDownList

Hi.

(For information, i'm working in VB.NET)
I have a datagrid on my page.
On its creation, I add a dropdownlist in each cell, with a different ID
each time.
This works fine.

But now, I can't access on the selected values of those dynamic
dropdownlists.
I tried this :
CType(Me.FindControl("ddlDay" & i), DropDownList).SelectedValue
But this generates me an error that says that this control doesn't
exists...
What am I doing wrong ???

Thanks for your help....
Dec 16 '05 #1
4 1956
Hi,
Your problem comes from the FindControl method wich is not recursive.
The best method shoud be to create a common eventHandler for all yours
dropdownlists, for example : DropDownLists_SelectedIndexChanged
and add the handler dynamicaly, with the following code when you add the
dropdownlists in the cells
code :
dim myDropdown as new DropDownList()
myDropdown.ID=ddlDay" & i
e.item.cells(0).add(myDropdown)
AddHandler myDropdown.SelectedIndexChanged, AddressOf
DropDownLists_SelectedIndexChanged

If the dropdownlist where added in a template column, it whould be easier,
the association whould be made declaratively with the OnSelectedIndexChanged
attribute.

--
Daniel TIZON
MCP - MCSD.NET - MCT

"TheHach" <Th*****@thehach.com> a écrit dans le message de news:
Xn*******************************@194.2.0.23...
Hi.

(For information, i'm working in VB.NET)
I have a datagrid on my page.
On its creation, I add a dropdownlist in each cell, with a different ID
each time.
This works fine.

But now, I can't access on the selected values of those dynamic
dropdownlists.
I tried this :
CType(Me.FindControl("ddlDay" & i), DropDownList).SelectedValue
But this generates me an error that says that this control doesn't
exists...
What am I doing wrong ???

Thanks for your help....

Dec 16 '05 #2
"Daniel TIZON" <da********************@hotmail.com> wrote in
news:ej**************@TK2MSFTNGP14.phx.gbl:
Hi,
Your problem comes from the FindControl method wich is not recursive.
The best method shoud be to create a common eventHandler for all yours
dropdownlists, for example : DropDownLists_SelectedIndexChanged
and add the handler dynamicaly, with the following code when you add
the dropdownlists in the cells
code :
dim myDropdown as new DropDownList()
myDropdown.ID=ddlDay" & i
e.item.cells(0).add(myDropdown)
AddHandler myDropdown.SelectedIndexChanged, AddressOf
DropDownLists_SelectedIndexChanged

If the dropdownlist where added in a template column, it whould be
easier, the association whould be made declaratively with the
OnSelectedIndexChanged attribute.


Thanks for your answer.
But your solution is only to add an event on the dynamic dropdownlists,
isn't it ?
My problem is that I have a datagrid with one column for each day of the
selected month, and a dropdownlist in each column. And when I click on
the submit button, I want to recover the selected value from each
dropdownlist. And I think your solution won't help me for this.
Do you have another one ??
Thanks in advance.
Dec 19 '05 #3
Hi,
Sorry to have misunderstood your scenario.
You need to get all the references of all yours Dropdownlist to tests their
selected value when you click on a button of the page.
All the references of the dropdownlist are reachable in the treecontrols of
the page. You can browse recusrsively the controls ins the page or in the
DataGrid and play with the controls of type DropDownlist. This must work,
but is not the most effective.
Another solution is to create your own collection of DropdDownLists :
- declare a member variable of type ArrayList in the class of your Page
- create the instance in the Page_Init
- In the event where you creates the Dropdownlist controls, probably in
DataGrid1_ItemCreated, add the ComboBox to the collection of the ArrayList
- In the Click EventHandler of the button, use a For each loop to play with
the list of your dropdownlists.

Hope this helps,

--
Daniel TIZON
MCP - MCSD.NET - MCT

"TheHach" <Th*****@thehach.com> a écrit dans le message de news:
Xn*******************************@194.2.0.23...
"Daniel TIZON" <da********************@hotmail.com> wrote in
news:ej**************@TK2MSFTNGP14.phx.gbl:
Hi,
Your problem comes from the FindControl method wich is not recursive.
The best method shoud be to create a common eventHandler for all yours
dropdownlists, for example : DropDownLists_SelectedIndexChanged
and add the handler dynamicaly, with the following code when you add
the dropdownlists in the cells
code :
dim myDropdown as new DropDownList()
myDropdown.ID=ddlDay" & i
e.item.cells(0).add(myDropdown)
AddHandler myDropdown.SelectedIndexChanged, AddressOf
DropDownLists_SelectedIndexChanged

If the dropdownlist where added in a template column, it whould be
easier, the association whould be made declaratively with the
OnSelectedIndexChanged attribute.


Thanks for your answer.
But your solution is only to add an event on the dynamic dropdownlists,
isn't it ?
My problem is that I have a datagrid with one column for each day of the
selected month, and a dropdownlist in each column. And when I click on
the submit button, I want to recover the selected value from each
dropdownlist. And I think your solution won't help me for this.
Do you have another one ??
Thanks in advance.

Dec 19 '05 #4
"Daniel TIZON" <da********************@hotmail.com> wrote in
news:e$**************@TK2MSFTNGP09.phx.gbl:
Hi,
Sorry to have misunderstood your scenario.
You need to get all the references of all yours Dropdownlist to tests
their selected value when you click on a button of the page.
All the references of the dropdownlist are reachable in the
treecontrols of the page. You can browse recusrsively the controls ins
the page or in the DataGrid and play with the controls of type
DropDownlist. This must work, but is not the most effective.
Another solution is to create your own collection of DropdDownLists :
- declare a member variable of type ArrayList in the class of your
Page - create the instance in the Page_Init
- In the event where you creates the Dropdownlist controls, probably
in DataGrid1_ItemCreated, add the ComboBox to the collection of the
ArrayList - In the Click EventHandler of the button, use a For each
loop to play with the list of your dropdownlists.

Hope this helps,


This works fine !
Thanks a lot !
Dec 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hb | last post by:
Hi, I have a page bill.aspx and its code-behind bill.aspx.cs. On bill.aspx I have: === Select a month: <asp:dropdownlist runat="server" id="lstDate" autopostback="True" /> <br> <asp:table...
5
by: mytestemailaccount | last post by:
Hi, Hope you can help. I am relatively new to all this but would appreciate the groups help. The scenario: I am c# and asp.net to create a web application. The web page contains a user...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
0
by: imranabdulaziz | last post by:
hi all , i am mess with the one situation. i am using asp.net2.0 ,C# and sql server 2005. I have checkboxlist and based on user selection i creates dynamic controls(which code is in...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
4
by: =?Utf-8?B?RHlsYW5TbWl0aA==?= | last post by:
I have a WebForm where I'm dynamically creating some controls and I'm having difficulty understanding how the state is being persisted and how to work with it. I've created a simplified example...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.