.NET (asp:Dropdownlist, javascript)

  • Thread starter Urmal Patel via .NET 247
  • Start date
U

Urmal Patel via .NET 247

I have problem with asp:Dropdownlist. I have a dropdownlist control in Page1.aspx and I want to assign value and Text to dropdown list form Page2.aspx from java script function. I am able to assign values to asp:textbox but not asp:dropdownlist

code is as follow when i call this function BindShipper();

function BindShipper(SearchResultFor, vendorID, localID,companyName, companyAdd1, companyAdd2, companyCity, companyState, companyZip, companyCountry, companyContact, companyComment, companyPhone, companyFax, companyEmail)
{
window.opener.document.Form1.txtShipperComment.value = companyComment;
window.opener.document.Form1.txtShipperCompanyName.value = companyName;
window.opener.document.Form1.txtShipperAddress1.value = companyAdd1;
window.opener.document.Form1.txtShipperAddress2.value = companyAdd2;
window.opener.document.Form1.txtShipperCity.value = companyCity;
//window.opener.document.Form1.ddlShipperState.Items.Add(companyState);
window.opener.document.Form1.txtShipperZip.value = companyZip;
//window.opener.document.Form1.ddlShipperCountry.Items.Insert(0,companyCountry); // where "0" is the value for this selection

//ListItem litShipperState = new ListItem("--Select--","");
//ddlState.Items.Insert(0,litShipperState);
//ddlState.Items[0].Selected = true;
}
 
M

mortb

Urmal Patel via .NET 247 said:
I have problem with asp:Dropdownlist. I have a dropdownlist control in
Page1.aspx and I want to assign value and Text to dropdown list form
Page2.aspx from java script function. I am able to assign values to
asp:textbox but not asp:dropdownlist
code is as follow when i call this function BindShipper();

function BindShipper(SearchResultFor, vendorID, localID,companyName,
companyAdd1, companyAdd2, companyCity, companyState, companyZip,
companyCountry, companyContact, companyComment, companyPhone, companyFax,
companyEmail)
{
window.opener.document.Form1.txtShipperComment.value = companyComment;
window.opener.document.Form1.txtShipperCompanyName.value = companyName;
window.opener.document.Form1.txtShipperAddress1.value = companyAdd1;
window.opener.document.Form1.txtShipperAddress2.value = companyAdd2;
window.opener.document.Form1.txtShipperCity.value = companyCity;
//window.opener.document.Form1.ddlShipperState.Items.Add(companyState);
window.opener.document.Form1.txtShipperZip.value = companyZip;
//window.opener.document.Form1.ddlShipperCountry.Items.Insert(0,companyCount
ry); // where "0" is the value for this selection
//ListItem litShipperState = new ListItem("--Select--","");
//ddlState.Items.Insert(0,litShipperState);
//ddlState.Items[0].Selected = true;
}

Do you want to add an element to a dropdown list using client side java
script?
Your code seems to have mixed up clientside and server side programming.
I think what you want to do (client side) is something like:

var newOptionElement = document.createElement("<option value='" + yourValue
+ "'>" + yourtext + "</option>";
window.opener.document.Form1.ddlShipperState.add(newOptionElement);

http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/document2/createelement.asp
http://msdn.microsoft.com/library/d...mshtml/reference/ifaces/selectelement/add.asp


cheers,
mortb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,266
Latest member
DavidaAlla

Latest Threads

Top