By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,781 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,781 IT Pros & Developers. It's quick & easy.

formview and dropdownlist

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.