Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0DropDownList is behaving strange !DropDownList is behaving strange !
Previous
 
Next
New Post
11/22/2007 7:28 AM
 

Hi there,
 There is a problem regarding DropDownList Control. Actually i  am trying to assign the list a particular field from the access database. And after that by selecting any element on that dropdownlist i want that the selection be querried and the result should be displayed on the other dropdownlist.
Everthing is done successfully BUT....
 [PROBLEM] Each time the page posted back, the number of elements get doubled and trippled on the first and second dropdownlist. I tried not to postback and played with viewstate of the page but all in vain.
 Please think about it.

Here is the sample code i m trying to run.

void Page_Load(Object s,EventArgs e)
{
  objConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("/") + "aeg.mdb");
  objConn.Open();
  objCmd = new OleDbCommand("SELECT DISTINCT Country from Institutes",objConn);
  objReader = objCmd.ExecuteReader();
  while(objReader.Read())
   {
   DropDownList6.Items.Add(Convert.ToString(objReader["Country"]));
   }
}

Then on Selected Index change:

void DropDownList6_SelectedIndexChanged(object sender, EventArgs e) {

 objCmd = new OleDbCommand("SELECT DISTINCT City from Institutes where Country = '"+ DropDownList6.SelectedItem.Text + "'",objConn);
objReader = objCmd.ExecuteReader();

  while(objReader.Read())
   {
  DropDownList7.Items.Add(Convert.ToString(objReader["City"]));

    }

}

Mangol.

 
New Post
11/26/2007 8:00 PM
 

Mangol,

In the page load, add:

If  !ispostback {

add items here

}

In the selected index change, add:

DropDownList7.Items.Clear

then add items

Hope this helps....

Steve

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0DropDownList is behaving strange !DropDownList is behaving strange !


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out