dropdownlist blues - can't bind datasource to datareader in codebehind

Discussion in 'ASP .Net Web Controls' started by Phil Streiff, Apr 24, 2004.

  1. Phil Streiff

    Phil Streiff Guest

    I prototyped a data-entry webform w/ c# & inline aspx. After I got it
    working, I tried to split my code out to a codebehind file (.cs) & now
    my dropdownlist isn't populating with choices for the user to select.

    Here's my code:
    --------------------------------------------------

    public void Page_Load (object sender, System.EventArgs e) {
    if(!IsPostBack) {
    SqlConnection myConn = new
    SqlConnection(ConfigurationSettings.AppSettings["connString"]);
    SqlCommand acctCmd = new SqlCommand("sp_Get_AccountType");
    acctCmd.CommandType = CommandType.StoredProcedure;

    myConn.Open();
    SqlDataReader drAccount = acctCmd.ExecuteReader();

    //Set up the data binding.
    ddlAcctType.DataSource = drAccount;
    ddlAcctType.DataTextField = "AccountType";
    ddlAcctType.DataValueField = "AcctTypeID";
    ddlAcctType.DataBind();

    //Close the connection.
    myConn.Close();
    drAccount.Close();

    //Add the item at the first position.
    ddlAcctType.Items.Insert(0, "<---- Select ---->");
    }
    }
    -----------------------------------------------------
    here is aspx reference:
    <asp:DropDownList id=ddlAcctType runat="server"
    width="200px"></asp:DropDownList>
    -----------------------------------------------------

    The .aspx page now displays with no errors but the dropdownlist
    appears empty. What am I doing wrong that's causing the ddl to not
    populate in codebehind?

    TIA,
    Phil
    Phil Streiff, Apr 24, 2004
    #1
    1. Advertising

  2. Phil Streiff

    Teemu Keiski Guest

    Hi,

    a) confirm that the code is generally running
    b) If it is, then check that should the procedure in question returns
    something e.g is there any data?

    a) Seems to be the problem because even at the first time doesn't seem to
    get to the DDL.


    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    "Phil Streiff" <> wrote in message
    news:...
    I prototyped a data-entry webform w/ c# & inline aspx. After I got it
    working, I tried to split my code out to a codebehind file (.cs) & now
    my dropdownlist isn't populating with choices for the user to select.

    Here's my code:
    --------------------------------------------------

    public void Page_Load (object sender, System.EventArgs e) {
    if(!IsPostBack) {
    SqlConnection myConn = new
    SqlConnection(ConfigurationSettings.AppSettings["connString"]);
    SqlCommand acctCmd = new SqlCommand("sp_Get_AccountType");
    acctCmd.CommandType = CommandType.StoredProcedure;

    myConn.Open();
    SqlDataReader drAccount = acctCmd.ExecuteReader();

    //Set up the data binding.
    ddlAcctType.DataSource = drAccount;
    ddlAcctType.DataTextField = "AccountType";
    ddlAcctType.DataValueField = "AcctTypeID";
    ddlAcctType.DataBind();

    //Close the connection.
    myConn.Close();
    drAccount.Close();

    //Add the item at the first position.
    ddlAcctType.Items.Insert(0, "<---- Select ---->");
    }
    }
    -----------------------------------------------------
    here is aspx reference:
    <asp:DropDownList id=ddlAcctType runat="server"
    width="200px"></asp:DropDownList>
    -----------------------------------------------------

    The .aspx page now displays with no errors but the dropdownlist
    appears empty. What am I doing wrong that's causing the ddl to not
    populate in codebehind?

    TIA,
    Phil
    Teemu Keiski, Apr 25, 2004
    #2
    1. Advertising

  3. Phil Streiff

    Phil Streiff Guest

    Teemu:

    Thanks for your reply. Per your suggestion, I tried to compile my .cs
    file and got the following message:

    Error CS5001 MaSSCRequest.aspx.exe does not have an entry point
    defined. Normal termination.

    I'll do some research to find out what this means. If you have any
    ideas, let me know.

    TIA,
    Phil
    Phil Streiff, Apr 25, 2004
    #3
  4. Phil Streiff

    Teemu Keiski Guest

    Umm...that sounds like you have wrong type of VS project in use? Compiling
    ASP.NET project will never result into an exe file (or why would it have
    aspx.exe file in use).

    Check the project options and there everything related to the
    compilation/project type.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke

    "Phil Streiff" <> wrote in message
    news:...
    Teemu:

    Thanks for your reply. Per your suggestion, I tried to compile my .cs
    file and got the following message:

    Error CS5001 MaSSCRequest.aspx.exe does not have an entry point
    defined. Normal termination.

    I'll do some research to find out what this means. If you have any
    ideas, let me know.

    TIA,
    Phil
    Teemu Keiski, Apr 25, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jake S
    Replies:
    2
    Views:
    1,680
    KathyB
    Jul 6, 2003
  2. mr2_93
    Replies:
    1
    Views:
    3,575
    mr2_93
    Oct 2, 2005
  3. rockdale
    Replies:
    0
    Views:
    507
    rockdale
    Jun 7, 2006
  4. Igor Stavnitser

    DataGrid with DropDownList blues

    Igor Stavnitser, Dec 31, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    82
    Igor Stavnitser
    Dec 31, 2004
  5. Replies:
    0
    Views:
    151
Loading...

Share This Page