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

dropdownlist problem - HELP URGENT

P: 2

i have a problem with a dropdown list i am populating from an Access table.
Ive seen this problem in other discussions but i cant seem to find the solution. please help.

my .aspx has the following inside a form:

[HTML]<asp:DropDownList id="_Pais" runat="server">
<asp:RequiredFieldValidator id="vr_Pais" runat="server" ControlToValidate="_Pais" Display="None" EnableClientScript="false" ></asp:RequiredFieldValidator>[/HTML]

my .aspx.cs has the following inside a function, which is not Page_Load, but is called upon just before the html code in the .aspx:

Expand|Select|Wrap|Line Numbers
  1. string qryP = "SELECT PaisES AS Texto, PaisES AS Valor FROM Paises ORDER BY PaisES";
  3. OleDbConnection cnP = new OleDbConnection(
  4.                     System.Configuration.ConfigurationSettings.AppSettings["accessConnectionString"]);
  5. cnP.Open();
  6. OleDbDataAdapter daP = new OleDbDataAdapter(qryP, cnP);
  7. OleDbCommandBuilder cbP = new OleDbCommandBuilder(daP);
  8. DataSet dsP = new DataSet();
  9. daP.Fill(dsP, "Paises");
  11. ((DropDownList)GetControl("_Pais")).DataSource = dsP.Tables["Paises"].DefaultView;
  12. ((DropDownList)GetControl("_Pais")).DataTextField= "Texto";
  13. ((DropDownList)GetControl("_Pais")).DataValueField= "Valor";
  14. ((DropDownList)GetControl("_Pais")).DataBind();
  16. cnP.Close();
  18. ((DropDownList)GetControl("_Pais")).Items.Insert(0, "-Select-");
  20. if (!Page.IsPostBack)
  21. {
  22.        ((DropDownList)GetControl("_Pais")).Items.FindByText("-Select-").Selected = true;
  23. }
The dropdownl list populates just fine. but when i press submit, the RequiredFieldValidator acts as if there was no item selected. If i take away the RequiredFieldValidator, the submit will work just fine, and the selected item will be saved into the DB.

Please help, i'm on a deadline :( :confused:
Aug 8 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.