protected void childrenGridView_SelectedIndexChanged(object sender, EventArgs e) //Redirect to child's profile { int childID = (int)childrenGridView.DataKeys[childrenGridView.SelectedRow.RowIndex]["userID"]; //Get id of selected row Child child = null; foreach (Child c in parent.Children) //Get object from childs id { if (c.ID == childID) { child = c; } } //Redirect to child's profile Session["childProfile"] = new ChildDAOImpl().getChild(child.Username, child.Password);//Get refreshed data for child Response.Redirect("~/childProfile.aspx"); }
protected void childrenGridView_RowCommand(object sender, GridViewCommandEventArgs e) // Upload images { if (e.CommandName.ToLower() != "upload") //Check if user pressed upload link { return; } Button bts = e.CommandSource as Button; GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer; //Get the selected row int childID = (int)childrenGridView.DataKeys[row.RowIndex]["userID"]; //Get child ID for selected row Child child = null; foreach (Child c in parent.Children) //Get child object from childID { if (c.ID == childID) { child = c; } } FileUpload fu = bts.FindControl("imageUpload") as FileUpload; //Get FileUpload control from html if (fu.HasFile) //Check if file was inserted { string extension = Path.GetExtension(fu.FileName); //Get file extension if ((extension.Trim().ToLower() == ".jpg") || (extension.Trim().ToLower() == ".png") || (extension.Trim().ToLower() == ".jpeg")) //Check if the image is in .png .jpg or .jpeg { if (child.ImageUrl != "") { File.Delete(Server.MapPath(child.ImageUrl)); //Delete the previous image of that child } var filePath = "~/Content/childrenImages/" + "profilePicture_userID_" + child.ID + extension; fu.SaveAs(Server.MapPath(filePath)); //Add new image child.ImageUrl = filePath; ChildDAO childDAO = new ChildDAOImpl(); childDAO.updateChild(child); //Update image directory string in DB bindGrid(); //Update the gridview to display new image } } }