//private String strcon = ConfigurationManager.ConnectionStrings["hr"].ConnectionString; //private dropdownlist ddlTest; protected void bindDropDownLists() { string myConnection = "dsn=myOracle;uid=system;pwd=oracle1"; OdbcConnection myConn = new OdbcConnection(myConnection); myConn.Open(); string mySelectQuery = "select utl_raw.cast_to_varchar2(UTL_RAW.cast_to_raw(id)) as id, name from servicetype;"; OdbcCommand command = new OdbcCommand(mySelectQuery, myConn); DataTable table = new DataTable(); OdbcDataAdapter adapter = new OdbcDataAdapter(command); adapter.Fill(table); ServiceDropDownList.DataSource = table; ServiceDropDownList.DataTextField = "name"; ServiceDropDownList.DataValueField = "id"; ServiceDropDownList.DataBind(); mySelectQuery = "select utl_raw.cast_to_varchar2(UTL_RAW.cast_to_raw(id)) as id, name from customer;"; command = new OdbcCommand(mySelectQuery, myConn); table = new DataTable(); adapter = new OdbcDataAdapter(command); adapter.Fill(table); CustomerDropDownList.DataSource = table; CustomerDropDownList.DataTextField = "name"; CustomerDropDownList.DataValueField = "id"; CustomerDropDownList.DataBind(); myConn.Close(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand sqlcmd = new SqlCommand("select * from Services ", con); ServiceDropDownList.DataSource = sqlcmd.ExecuteReader(); ServiceDropDownList.DataBind(); con.Close(); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand sqlcmd2 = new SqlCommand("select * from items ", con); itemDropDownList.DataSource = sqlcmd2.ExecuteReader(); itemDropDownList.DataBind(); } }
protected void FillDropDownList() { //Declare the dataTabe DataTable table = null;; try { //call the method in the class to fill the table table = gs.GetServices(); } catch (Exception ex) { ErrorLabel.Text = ex.Message; } //Attach the table as a datasource for the //drop down list //assign the display and value fields ServiceDropDownList.DataSource = table; ServiceDropDownList.DataTextField = "ServiceName"; ServiceDropDownList.DataValueField = "ServiceKey"; ServiceDropDownList.DataBind(); }