protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e) { PastProjects.DataSource = SqlDataSource2; SqlDataSource2.Select(DataSourceSelectArguments.Empty); PastProjects.DataTextField = "name"; PastProjects.DataValueField = "project_ID"; PastProjects.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PastProjects.DataTextField = "name"; PastProjects.DataValueField = "project_ID"; PastProjects.DataBind(); GridView1.Visible = false; TaskButton.Visible = false; FormView1.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Add.Visible = false; projectview.Visible = false; ProjectManager.DataSource = SqlDataSource1; ProjectManager.DataTextField = "last_name"; ProjectManager.DataValueField = "ssn"; ProjectManager.DataBind(); PastProjects.DataSource = SqlDataSource2; PastProjects.DataTextField = "name"; PastProjects.DataValueField = "project_ID"; PastProjects.DataBind(); } }
protected void Insert_ButtonClick(object sender, EventArgs e) { //Parse form values String name = Name.Text; String pm = ProjectManager.SelectedValue; String start = Request.Form["startdate"]; DateTime start_date = Convert.ToDateTime(start); String completion = Request.Form["completiondate"]; DateTime completion_date = Convert.ToDateTime(completion); String project_type = Type.SelectedValue; String description = Description.Text; Int32 budget = Convert.ToInt32(Budget.Text); //Execute the SQL Insert try { String DataConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Public_Works_Project"].ConnectionString; String Insert = "Insert into dbo.Project VALUES (@pm, @name, @start_date, @completion_date, @project_type, @description, @budget);"; SqlConnection Connection = new SqlConnection(DataConnectionString); Connection.Open(); using (SqlCommand Command = new SqlCommand(Insert, Connection)) { SqlParameter the_name = new SqlParameter("name", DbType.String); the_name.Value = name; Command.Parameters.Add(the_name); SqlParameter the_pm = new SqlParameter("pm", DbType.String); the_pm.Value = pm; Command.Parameters.Add(the_pm); SqlParameter the_start = new SqlParameter("start_date", DbType.String); the_start.Value = start_date; Command.Parameters.Add(the_start); SqlParameter the_completion = new SqlParameter("completion_date", DbType.String); the_completion.Value = completion_date; Command.Parameters.Add(the_completion); SqlParameter the_project_type = new SqlParameter("project_type", DbType.String); the_project_type.Value = project_type; Command.Parameters.Add(the_project_type); SqlParameter the_description = new SqlParameter("description", DbType.String); the_description.Value = description; Command.Parameters.Add(the_description); SqlParameter the_budget = new SqlParameter("budget", DbType.String); the_budget.Value = budget; Command.Parameters.Add(the_budget); Command.ExecuteNonQuery(); } } catch (Exception ex) { //log error //display friendly error to user } PastProjects.DataSource = SqlDataSource2; SqlDataSource2.Select(DataSourceSelectArguments.Empty); PastProjects.DataTextField = "name"; PastProjects.DataValueField = "project_ID"; PastProjects.DataBind(); Add.Visible = false; initial.Visible = true; projectview.Visible = false; }