예제 #1
0
        //ADDS IMAGE (TO GRIDVIEW)(or hides depending)
        public void AddImageToGridView()
        {
            //current project
            string currentProject = ProjectFolder.GetCurrentProject();

            //test (image folder exists)
            string imagePath = ProjectFolder.GetAspFolder() + "images\\" + currentProject;
            bool   testIfImageFolderExists = ImageFolderExists(imagePath);

            //test (image column exists)
            bool testIfColumnExists = TestColumn("Thumbnail");

            //get button column (image toggle)
            //int imageBtnIndex = GetColumn("Image Toggle");
            int imageBtnIndex = GetColumn("Toggle");

            //get column index
            int columnIndex = GetColumn("Thumbnail");
            //DataControlField cntl;
            ImageField img;

            //image path "/images/defaultProject/{0}"
            string imageAttrPath = "/images/" + currentProject + "/{0}";    //the {0} binds to Image column 'Piping/cd00001.jpg' (DataImageUrlField)

            //only do this if image folder exists (user needs to upload images)
            if (testIfImageFolderExists)
            {
                if (!testIfColumnExists)
                {
                    //(add) image column field
                    //ImageField img = new ImageField();
                    img = new ImageField();
                    img.DataImageUrlField = "Image";

                    //img.DataImageUrlFormatString = "/images/defaultProject/{0}";
                    img.DataImageUrlFormatString = imageAttrPath;
                    //img.DataImageUrlFormatString = imageAttrPath;

                    img.ControlStyle.Width  = 80;
                    img.ControlStyle.Height = 50;

                    img.AlternateText = "Clash Image";
                    img.HeaderText    = "Thumbnail";

                    //img.NullDisplayText = "Image not found, please load images from the settings menu.";
                    //img.NullImageUrl = "/images/404ImageNotFound.png";

                    img.Visible = true;                                             //show image
                    gvClashResult.Columns[imageBtnIndex].Visible = true;            //show button

                    gvClashResult.Columns.Add(img);
                }
                else
                {
                    //cntl = gvClashResult.Columns[columnIndex];
                    //ImageField img = (ImageField)gvClashResult.Columns[columnIndex];
                    img = (ImageField)gvClashResult.Columns[columnIndex];

                    //img.DataImageUrlFormatString = "/images/defaultProject/{0}";
                    img.DataImageUrlFormatString = imageAttrPath;

                    //need to push the WIDTH and HEIGHT (seems to be stripping out the attributes when dropdown changes)
                    img.ControlStyle.Width  = 80;
                    img.ControlStyle.Height = 50;

                    img.Visible = true;                                             //show image
                    gvClashResult.Columns[imageBtnIndex].Visible = true;            //show button
                }
            }
            //do this if there are (no image folder)
            else
            {
                //(remove) any image columns from previous project
                if (testIfColumnExists)
                {
                    //(hide) image column and button
                    img = (ImageField)gvClashResult.Columns[columnIndex];

                    //need to push the WIDTH and HEIGHT (seems to be stripping out the attributes when dropdown changes)
                    img.ControlStyle.Width  = 80;
                    img.ControlStyle.Height = 50;

                    img.Visible = false;                                             //hide image
                    gvClashResult.Columns[imageBtnIndex].Visible = false;            //hide button
                }
            }
        }