i have a problem with a dropdown list i am populating from an Access table.
I´ve seen this problem in other discussions but i can´t seem to find the solution. please help.
my .aspx has the following inside a form:
[HTML]<asp:DropDownLi st id="_Pais" runat="server">
</asp:DropDownLis t>
<asp:RequiredFi eldValidator id="vr_Pais" runat="server" ControlToValida te="_Pais" Display="None" EnableClientScr ipt="false" ></asp:RequiredFie ldValidator>[/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
- string qryP = "SELECT PaisES AS Texto, PaisES AS Valor FROM Paises ORDER BY PaisES";
- OleDbConnection cnP = new OleDbConnection(
- System.Configuration.ConfigurationSettings.AppSettings["accessConnectionString"]);
- cnP.Open();
- OleDbDataAdapter daP = new OleDbDataAdapter(qryP, cnP);
- OleDbCommandBuilder cbP = new OleDbCommandBuilder(daP);
- DataSet dsP = new DataSet();
- daP.Fill(dsP, "Paises");
- ((DropDownList)GetControl("_Pais")).DataSource = dsP.Tables["Paises"].DefaultView;
- ((DropDownList)GetControl("_Pais")).DataTextField= "Texto";
- ((DropDownList)GetControl("_Pais")).DataValueField= "Valor";
- ((DropDownList)GetControl("_Pais")).DataBind();
- cnP.Close();
- ((DropDownList)GetControl("_Pais")).Items.Insert(0, "-Select-");
- if (!Page.IsPostBack)
- {
- ((DropDownList)GetControl("_Pais")).Items.FindByText("-Select-").Selected = true;
- }
Please help, i'm on a deadline :( :confused: