473,394 Members | 1,866 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,394 software developers and data experts.

formview and dropdownlist

I have a set of maintenance forms which represent a parent child
relationship.
In the parent form you can set a value 1 to 5.
Say the user chooses 3.
In the child form the user should only get to choos from 1, 2 or 3 in
a dropdownlist.
This is within a formview.

If I declaratively add items 1 through 5 then everything works fine.
My problems started when I tried to switch to programmatically adding
the entries.
I get various errors depending on what event I stick my code into but
essentially I'm unable to find a page event whiere the dropdownlist
control can be found (FindControl) but which is before the
databinding
event.
Any ideas on how to get round this problem?
example code
protected void Page_Load(object sender, EventArgs e)
{
Key_Risk_Id_txt.Text = Request.QueryString["Risk_Id"];
Risk Current_Risk = new
Risk(Convert.ToInt32(Request.QueryString["Risk_Id"]));
int i;
DropDownList ddl =
(DropDownList)fvwMitigation.FindControl("S_Commerc ial_ddl");
for (i = 1; i <=
Convert.ToInt32(Current_Risk.S_Commercial); i++)
{
ddl.Items.Add(new ListItem(Convert.ToString(i),
Convert.ToString(i)));
}
}

Jan 29 '07 #1
1 2523
I got it working.
Using ItemCreated event of the formview.

On 29 Jan, 12:27, "andy" <a...@lycos.co.ukwrote:
I have a set of maintenance forms which represent a parent child
relationship.
In the parent form you can set a value 1 to 5.
Say the user chooses 3.
In the child form the user should only get to choos from 1, 2 or 3 in
a dropdownlist.
This is within a formview.

If I declaratively add items 1 through 5 then everything works fine.
My problems started when I tried to switch to programmatically adding
the entries.

I get various errors depending on what event I stick my code into but
essentially I'm unable to find a page event whiere the dropdownlist
control can be found (FindControl) but which is before the
databinding
event.

Any ideas on how to get round this problem?

example code

protected void Page_Load(object sender, EventArgs e)
{
Key_Risk_Id_txt.Text = Request.QueryString["Risk_Id"];
Risk Current_Risk = new
Risk(Convert.ToInt32(Request.QueryString["Risk_Id"]));
int i;
DropDownList ddl =
(DropDownList)fvwMitigation.FindControl("S_Commerc ial_ddl");
for (i = 1; i <=
Convert.ToInt32(Current_Risk.S_Commercial); i++)
{
ddl.Items.Add(new ListItem(Convert.ToString(i),
Convert.ToString(i)));
}
}
Jan 29 '07 #2

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

Similar topics

2
by: P. Yanzick | last post by:
Hello, I am creating an edit template for a FormView control, changing one of the textboxes to a dropdown box. The dropdown will be populated from a simple table with the primary key, and a...
0
by: Rabbit | last post by:
Hi, All, I have a FormView, in which the InsertItemTemplate has a dropdownlist that I need to set the datasource as my self created dataset. I have been trying various syntax like following at...
3
by: Bas Paap | last post by:
I'm having a problem with formviews and DropDownLists in ASP.NET 2.0. I'm using a formview to insert an order into a database. Part of the order is the customer. Currently, I have a dropdownlist...
3
by: sck10 | last post by:
Hello, I am trying to bind an arraylist to a FormView DropDownList control in the PreRender state. The error that I get is the following: Databinding methods such as Eval(), XPath(), and...
3
by: YMPN | last post by:
Hi Everyone, I'm deen from Riyadh. Please do help me with some problem i have. I have this formview control setup to recieved inputs from user (textbox, dropdownlist, others). After...
3
by: J055 | last post by:
Hi I have a PlaceHolder control inside a FormView EditItemTemplate: <asp:PlaceHolder ID="phResponseText" runat="server"> <tr> <td> <asp:Label ID="lblResponseText"...
1
by: Trev | last post by:
Hi, I'm hoping that someone in this group can shed some light on an issue I'm having with a Formview. I have a Web User Control (.ascx) with a Formview. The Formview contains 2 Multiviews,...
0
by: sgtmarcjones | last post by:
How do I access a dropdownlist that is nested within a Formview ItemTemplate Gridview Template? I want to see a label (lgbTimeKeep ! TextValue of ddlName dropdownlist) instead of a dropdownlist...
1
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is...
0
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.