[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

Bind dataTable to dropDownList

I'm trying to bind my drop down to a dataTable.
My drop down comes up blank.

Thanks.
 public void dropDownAssign()
    {

        OracleConnection oracleConn = new OracleConnection();
        oracleConn.ConnectionString = ConfigurationManager.ConnectionStrings["oracleConnectionString"].ConnectionString;

        string sql = "SELECT ASSIGNED,ASSIGNED_LAST_NAME,ASSIGNED_FIRST_NAME,ASSIGNED_MI,ASSIGNED_ID FROM ASSIGNED_LU";

        OracleCommand cmd = new OracleCommand(sql, oracleConn);

        //Create Oracle Data Adapter and Dataset then fill it.
        OracleDataAdapter asAdapter = new OracleDataAdapter(cmd);
        DataSet dt_assign = new DataSet();
        asAdapter.Fill(dt_assign);

        DataTable tblAssign = new DataTable();
        tblAssign.Columns.Add("fullName");
        tblAssign.Columns.Add("lastName");
        tblAssign.Columns.Add("firstName");
        tblAssign.Columns.Add("middleName");
        tblAssign.Columns.Add("assigned_ID");
        tblAssign.Columns.Add("assigned");

        foreach (DataRow dr in dt_assign.Tables[0].Rows)
        {
            DataRow drInsert = tblAssign.NewRow();
            drInsert["fullName"] = dr["ASSIGNED_LAST_NAME"] + ", " + dr["ASSIGNED_FIRST_NAME"];
            drInsert["lastName"] = dr["ASSIGNED_LAST_NAME"];
            drInsert["firstName"] = dr["ASSIGNED_FIRST_NAME"];
            drInsert["middleName"] = dr["ASSIGNED_MI"];
            drInsert["assigned_ID"] = dr["ASSIGNED_ID"];
            drInsert["assigned"] = dr["ASSIGNED"];
            tblAssign.Rows.Add(drInsert);           
        }
        assignedTo.DataSource = tblAssign;
        assignedTo.DataTextField = "fullName";
        assignedTo.DataValueField = "assigned_ID";
        assignedTo.DataBind();
    }

Open in new window

0
Isaac
Asked:
Isaac
1 Solution
 
Bob LearnedCommented:
Since it looks like that code is correct (as far as I can tell), what is supposed to call the "dropDownAssign" method?
0
 
princeatapiCommented:
// Try Using Accept Changes
tblAssign.AcceptChanges();
assignedTo.DataSource = tblAssign;
        assignedTo.DataTextField = "fullName";
        assignedTo.DataValueField = "assigned_ID";
        assignedTo.DataBind();
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now