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

Drop Down List Control , Select Value, and Javascript

P: n/a
Hi,

I've been asked to create a page that dynamically populates the contents of
related drop down lists using JavaScript, and then obviously posts things
back to the server.

For completeness, I re-produce example JavaScript below (this seemingly
works fine - but just to let you see what is going on)

e.g. var categoriesArray = TrendCategoriesHolder[intTrendIndex];
for ( i = 0; i <= categoriesArray.length - 1; i++)
{ var categoriesObject = categoriesArray[i];
var categoriesText = categoriesObject[0];
var categoriesValue = categoriesObject[2];
ddlTrendCategory.options[i] = new Option(categoriesText,
categoriesValue);
}
var ddlTrendType = document.getElementById("ddlTrendType");
ddlTrendCategory.options[ddlTrendCategory.options.length] = new
Option("All Categories", 0);
When I post this back to the server, if i use
ddlTrendCategory.SelectedValue.ToString() it claims it evalutates to "". If i
use ddlTrendCategory.SelectedItem.Value.ToString() then it errors, with a
null reference error.

So, seemingly ASP.NET is not recognising that the drop down list has
contents. Is there a way round this, or is the whole approach I was asked to
do invalid and doomed to fail!

Help appreciated. Thanks in avance.
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
you have to retrieve the value by yourself.
like:
request.form("mydropdown")
will contain the selected value of the dropdown.

if your dropdownlist is not populated from the server side, you can't use
the server side object model. from a server side point of view, the
dropdownlist is empty, so you can't select anything from this point of view.
"craig@amtdatatechnologies"
<cr**********************@discussions.microsoft.co m> wrote in message
news:4F**********************************@microsof t.com...
Hi,

I've been asked to create a page that dynamically populates the contents
of
related drop down lists using JavaScript, and then obviously posts things
back to the server.

For completeness, I re-produce example JavaScript below (this seemingly
works fine - but just to let you see what is going on)

e.g. var categoriesArray = TrendCategoriesHolder[intTrendIndex];
for ( i = 0; i <= categoriesArray.length - 1; i++)
{ var categoriesObject = categoriesArray[i];
var categoriesText = categoriesObject[0];
var categoriesValue = categoriesObject[2];
ddlTrendCategory.options[i] = new Option(categoriesText,
categoriesValue);
}
var ddlTrendType = document.getElementById("ddlTrendType");
ddlTrendCategory.options[ddlTrendCategory.options.length] = new
Option("All Categories", 0);
When I post this back to the server, if i use
ddlTrendCategory.SelectedValue.ToString() it claims it evalutates to "".
If i
use ddlTrendCategory.SelectedItem.Value.ToString() then it errors, with a
null reference error.

So, seemingly ASP.NET is not recognising that the drop down list has
contents. Is there a way round this, or is the whole approach I was asked
to
do invalid and doomed to fail!

Help appreciated. Thanks in avance.

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.