protected void LoadDDLprogetto() { conn.Open(); string sqlCmd; // visualizza solo progetti del manager if (!Auth.ReturnPermission("MASTERDATA", "PROJECT_ALL")) { sqlCmd = "Select Projects_id, ProjectCode + ' ' + left(Name,20) as iProgetto from Projects where ActivityOn = 1 and active = 1 AND ClientManager_id = " + CurrentSession.Persons_id + " ORDER BY iProgetto"; } else { sqlCmd = "Select Projects_id, ProjectCode + ' ' + left(Name,20) as iProgetto from Projects where ActivityOn = 1 and active = 1 ORDER BY iProgetto"; } SqlCommand cmd = new SqlCommand(sqlCmd, conn); SqlDataReader dr = cmd.ExecuteReader(); DropDownList ddlList = (DropDownList)FVattivita.FindControl("DDLprogetto"); ddlList.DataSource = dr; ddlList.Items.Clear(); ddlList.Items.Add(new ListItem("--Seleziona progetto--", "")); ddlList.DataTextField = "iProgetto"; ddlList.DataValueField = "Projects_Id"; if (Request.QueryString["Projects_id"] != null) // in caso di update seleziona il valore nella dropdown list { ddlList.SelectedValue = Request.QueryString["Projects_id"].ToString(); } ddlList.DataBind(); conn.Close(); }
protected void ItemInserting_FVattivita(object sender, FormViewInsertEventArgs e) { // Forza i valori da passare alla select di insert. essendo le dropdown in // dipendenza non si riesce a farlo tramite un normale bind del controllo DropDownList ddlList = (DropDownList)FVattivita.FindControl("DDLprogetto"); e.Values["Projects_id"] = ddlList.SelectedValue; DropDownList ddlList1 = (DropDownList)FVattivita.FindControl("DDLFase"); e.Values["Phase_id"] = ddlList1.SelectedValue; }
public void Bind_ddlFase() { conn.Open(); DropDownList ddlprogetto = (DropDownList)FVattivita.FindControl("DDLProgetto"); SqlCommand cmd = new SqlCommand("select Phase_id, PhaseCode + ' ' + left(Name,20) AS iFase FROM Phase where Projects_id='" + ddlprogetto.SelectedValue + "' ORDER BY iFase", conn); SqlDataReader dr = cmd.ExecuteReader(); DropDownList ddlList = (DropDownList)FVattivita.FindControl("DDLFase"); ddlList.DataSource = dr; ddlList.Items.Clear(); ddlList.Items.Add(new ListItem("--Seleziona fase--", "")); ddlList.DataTextField = "iFase"; ddlList.DataValueField = "Phase_id"; if (Request.QueryString["Phase_Id"] != null && !IsPostBack) // in caso di update seleziona il valore nella dropdown list { ddlList.SelectedValue = Request.QueryString["Phase_Id"]; } ddlList.DataBind(); conn.Close(); }