private void LoadData() { btnClose.OnClientClick = ActiveWindow.GetHideReference(); DataSet ds = m_bllCK_ProductType.GetList(""); DropDownListProductType.DataTextField = "CK_ProductTypeName"; DropDownListProductType.DataValueField = "CK_ProductTypeID"; DropDownListProductType.DataSource = ds.Tables[0]; DropDownListProductType.DataBind(); DropDownListProductType.SelectedIndex = 0; int id = GetQueryIntValue("id"); TSM.Model.CK_Product modelCK_Product = m_bllCK_Product.GetModel(id); if (modelCK_Product == null) { // 参数错误,首先弹出Alert对话框然后关闭弹出窗口 Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference()); return; } tbxName.Text = modelCK_Product.CK_ProductName; tbxPrice.Text = modelCK_Product.CK_ProductPrice.ToString(); DropDownListProductType.SelectedValue = modelCK_Product.CK_ProductTypeID.ToString(); }
private void LoadData() { btnClose.OnClientClick = ActiveWindow.GetHideReference(); DataSet ds = m_bllCK_ProductType.GetList(""); DropDownListProductType.DataTextField = "CK_ProductTypeName"; DropDownListProductType.DataValueField = "CK_ProductTypeID"; DropDownListProductType.DataSource = ds.Tables[0]; DropDownListProductType.DataBind(); DropDownListProductType.SelectedIndex = 0; }
protected void UpdateDropDownListProductType() { SqlConnection conn = new SqlConnection(dbconfig); SqlDataAdapter da = null; DataSet ds = null; DataTable dt = null; string sqlsel = "SELECT IdProductType, Name FROM ProductType"; try { // conn.Open(); SqlDataAdapter open the connection by itself da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(sqlsel, conn); ds = new DataSet(); da.Fill(ds, "ProductType"); dt = ds.Tables["ProductType"]; // populate the dropdownlist DropDownListProductType.Items.Clear(); DropDownListProductType.DataSource = dt; DropDownListProductType.DataTextField = "Name"; DropDownListProductType.DataValueField = "IdProductType"; DropDownListProductType.DataBind(); DropDownListProductType.Items.Insert(0, "Select a Producttype"); //Select the Company of the selected product string productType = GridViewProduct.SelectedRow.Cells[8].Text; DropDownListProductType.Items.FindByValue(productType).Selected = true; } catch (Exception ex) { LabelMessageProduct.Text = ex.Message; } finally { // SqlDataAdapter closes the connection by itself, but can fail in case of errors conn.Close(); } }
protected void UpdateDropDownListProductType() { // Create a db connection with configuration from web.config SqlConnection conn = new SqlConnection(dbconfig); //SqlConnection conn = new SqlConnection(@"data source = .\SQLEXPRESS; integrated security = true; database = CMSdb"); SqlDataAdapter da = null; DataSet ds = null; DataTable dt = null; string sqlsel = "SELECT IdProductType, Name FROM ProductType"; try { // conn.Open(); SqlDataAdapter open the connection by itself da = new SqlDataAdapter(); da.SelectCommand = new SqlCommand(sqlsel, conn); ds = new DataSet(); da.Fill(ds, "ProductType"); dt = ds.Tables["ProductType"]; // populate the dropdownlist DropDownListProductType.Items.Clear(); DropDownListProductType.DataSource = dt; DropDownListProductType.DataTextField = "Name"; DropDownListProductType.DataValueField = "IdProductType"; DropDownListProductType.DataBind(); DropDownListProductType.Items.Insert(0, "Select a Producttype"); } catch (Exception ex) { LabelMessageProduct.Text = ex.Message; } finally { // SqlDataAdapter closes the connection by itself, but can fail in case of errors conn.Close(); } }