Problem getting a DropDownList populated by query(beginner)

G

Guest

Hi,
I am trying to get a DropDownList to be populated by a simple query, but I
cannot see why it doesn't work, I was hoping someone can shed some light for
me.

Here's my C# code:

private void Page_Load(object sender, System.EventArgs e)
{
//strConn = ConfigurationSettings.AppSettings["SqlConnect"];
DataSet ds = new DataSet();
DataView dv = new DataView();

SqlConnection objConn = new
SqlConnection(ConfigurationSettings.AppSettings["SqlConnect"]);

SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT RSL, FullName
FROM tbl_Contacts_2005", objConn);
myDataAdapter.Fill(ds, "RSLNames");
dv = ds.Tables["RSLNames"].DefaultView;
ddlRSL.DataSource = dv;
ddlRSL.DataValueField = "RSL";
ddlRSL.DataTextField = "FullName";
ddlRSL.DataBind();
}

And heres my DropDownList tag:

<asp:DropDownList id="ddlRSL" runat="server" />

I cannot see why it doesn't work.

Any ideas?
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top