/// <summary> /// 绑定下拉列表(数据显示控件或者源数据集不存在都会引发异常) /// </summary> /// <param name="rbtnl">数据显示控件</param> /// <param name="ds">数据集</param> /// <param name="DataTextField">文本数据源</param> /// <param name="DataValueField">值数据源</param> /// <param name="hasTopItem">bool,是否有默认第一项</param> /// <param name="topItemText">第一项文本</param> /// <param name="topItemValue">第一项值</param> public static void Bind(System.Web.UI.WebControls.RadioButtonList rbtnl, DataSet ds, string DataTextField, string DataValueField, bool hasTopItem, string topItemText, string topItemValue) { if (rbtnl != null) { if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { rbtnl.ClearSelection(); rbtnl.Items.Clear(); rbtnl.DataTextField = DataTextField; rbtnl.DataValueField = DataValueField; rbtnl.DataSource = ds.Tables[0].DefaultView; rbtnl.DataBind(); if (hasTopItem) { ListItem lit = new ListItem(topItemText, topItemValue); rbtnl.Items.Insert(0, lit); } } else { throw new Exception("源数据集不存在"); } } else { throw new Exception("数据控件不存在"); } }
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { PrepareThemeAndModifierOptions(DropDownList1.SelectedValue); RadioButtonList1.ClearSelection(); CheckBoxList1.ClearSelection(); CleanUp(GetMapObj()); }
/// <summary> /// Selects and item in the radio button list control by the item value. /// This is available as a property of the control in .Net 1.1 /// </summary> /// <param name="control"></param> /// <param name="value"></param> public static void SelectItem(RadioButtonList control, string value) { control.ClearSelection(); ListItem item = control.Items.FindByValue(value); if (item != null) item.Selected = true; }
public static void SetListValue(System.Web.UI.WebControls.RadioButtonList myListControl, object _Value) { myListControl.ClearSelection(); if (myListControl.Items.Count == 1) { myListControl.SelectedIndex = 0; } else { foreach (ListItem _item in myListControl.Items) { if (_item.Value.ToString().ToLower() == _Value.ToString().ToLower()) { _item.Selected = true; break; } } } }
public void SelectValueRadio(RadioButtonList RadioButtonList, string value) { ListItem item = RadioButtonList.Items.FindByValue(value); if (item != null) { RadioButtonList.ClearSelection(); item.Selected = true; } }
/* * Uploads posted images upon verification */ //private string[] UpLoadAllImages(string[] strImgPathArray) private BlogStruct UpLoadAllImages(ref BlogStruct tmpStruct) { string tmpFile; string thmbNailPath; string userDir = ""; //get user dir userDir = Session["userDir"].ToString(); //if panel is open check for loaded img files if (pnlAddImages.Visible) { //Collect files names, iterate through each and update accordingly HttpFileCollection uploadFilCol = System.Web.HttpContext.Current.Request.Files; int count = uploadFilCol.Count; //loop thru for each posted file for (int i = 0; i < count; i++) { //get handle to file HttpPostedFile file = uploadFilCol[i]; if (file.ContentLength > (int)0) { //get file name & ext string fileName = Path.GetFileName(file.FileName); string fileExt = Path.GetExtension(file.FileName).ToLower(); string tmpDir = AppDomain.CurrentDomain.BaseDirectory + @"\users\" + userDir + @"\temp\"; //check for temp dir and create if non-existent if (!(Directory.Exists(tmpDir))) { //'E:\kunden\homepages\31\d213027625\Showcase\users\0\0\0\0\0\0\0\1\6\2\temp\ Directory.CreateDirectory(tmpDir); } //get physical path to temp dir for upload string path = tmpDir; //Generate random file name tmpFile = GenerateRandomString(8).ToLower(); //concatenate renamed file with ext tmpFile = tmpFile + fileExt; //add together path and file name; This is our fully qualified *temp path where the file gets uploaded //strImgPathArray[i] = Path.Combine(path, tmpFile); tmpStruct.tmpArray[i] = Path.Combine(path, tmpFile); thmbNailPath = Path.Combine(path, "thmbNail_" + tmpFile); //Upload to temp dir; we'll write to perm directory after user confirms on preview! //FIXME: Check for file type and size if (fileName != string.Empty) { //resize the image and save //Create an image object from the uploaded file. try { System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(file.InputStream); //Larger Image variables int maxWidth = 300; int maxHeight = 300; int sourceWidth = UploadedImage.Width; int sourceHeight = UploadedImage.Height; int sourceX = 0; int sourceY = 0; int destX = 0; int destY = 0; float nPercent = 0; float nPercentW = 0; float nPercentH = 0; //ThumbNail variables int maxWidth_T = 150; int maxHeight_T = 150; int destX_T = 0; int destY_T = 0; float nPercent_T = 0; float nPercentW_T = 0; float nPercentH_T = 0; //Larger Image percents nPercentW = ((float)maxWidth / (float)sourceWidth); nPercentH = ((float)maxHeight / (float)sourceHeight); //Thumbnail percents nPercentW_T = ((float)maxWidth_T / (float)sourceWidth); nPercentH_T = ((float)maxHeight_T / (float)sourceHeight); //Find the biggest change(smallest pct) if (nPercentH < nPercentW) { //Larger Image Calculations nPercent = nPercentH; destX = System.Convert.ToInt16((maxWidth - (sourceWidth * nPercent)) / 2); //Thumbnail Calculations nPercent_T = nPercentH_T; destX_T = System.Convert.ToInt16((maxWidth_T - (sourceWidth * nPercent_T)) / 2); } else { //Larger Image Calculations nPercent = nPercentW; destY = System.Convert.ToInt16((maxHeight - (sourceHeight * nPercent)) / 2); //ThumbNail Calculations nPercent_T = nPercentW_T; destY_T = System.Convert.ToInt16((maxWidth_T - (sourceHeight * nPercent_T)) / 2); } //Larger Image Calculations int destWidth = (int)(sourceWidth * nPercent); int destHeight = (int)(sourceHeight * nPercent); //Smaller Image Calculations int destWidth_T = (int)(sourceWidth * nPercent_T); int destHeight_T = (int)(sourceHeight * nPercent_T); //create the larger bitmap Bitmap bmPhoto = new Bitmap(maxWidth, maxHeight); bmPhoto.SetResolution(UploadedImage.HorizontalResolution, UploadedImage.VerticalResolution); //create the thumbnail bitmap Bitmap bmPhotoThmbNail = new Bitmap(maxWidth_T, maxHeight_T); bmPhotoThmbNail.SetResolution(UploadedImage.HorizontalResolution, UploadedImage.VerticalResolution); //create larger graphic Graphics grPhoto = Graphics.FromImage(bmPhoto); grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; grPhoto.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; grPhoto.Clear(Color.Transparent); grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; grPhoto.DrawImage(UploadedImage, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel); //create thumbnail graphic Graphics grPhotoThmbNail = Graphics.FromImage(bmPhotoThmbNail); grPhotoThmbNail.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; grPhotoThmbNail.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; grPhotoThmbNail.Clear(Color.Transparent); grPhotoThmbNail.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; grPhotoThmbNail.DrawImage(UploadedImage, new Rectangle(destX_T, destY_T, destWidth_T, destHeight_T), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel); //int memberID = 0; //Save the Image(s) // (1) "Saves" the graphic. It really just updates the bitmap with the contents of the graphic. // Basically saving it in memory. // (2) Actually save the bitmap to the file system. //Larger grPhoto.Save(); // (1) bmPhoto.Save(tmpStruct.tmpArray[i]); // (2) .., ImageFormat.Jpeg) //strip out the superfluous server path and just save the file name; this was the cause of much grief as we were saving the entire path! tmpStruct.tmpArray[i] = Path.GetFileName(tmpStruct.tmpArray[i]); //Thumbnail grPhotoThmbNail.Save(); bmPhotoThmbNail.Save(thmbNailPath); //Find out who is set to "change" or "add" so we know who to update // - We call the clearSelection() to let ourselves know that index has been processed //TODO: append (&& File1.Value.Length>0) if (rdoImgMgr1.SelectedValue == "Change" || rdoImgMgr1.SelectedValue == "Add") { tmpStruct.sBlog.ImgPath1 = tmpStruct.tmpArray[i]; rdoImgMgr1.ClearSelection(); } else if (rdoImgMgr2.SelectedValue == "Change" || rdoImgMgr2.SelectedValue == "Add") { tmpStruct.sBlog.ImgPath2 = tmpStruct.tmpArray[i]; rdoImgMgr2.ClearSelection(); } } catch (Exception ex) { lblStatus.Text = "Resize/Save Error!"; } } else { tmpStruct.tmpArray[i] = string.Empty; } } } }//end main if //return strImgPathArray; return(tmpStruct); }
/* * Upload any images */ //private string[] UpLoadAllImages(BoardItem bItem, string[] strImgPathArray) private classes.Blog UpLoadAllImages(classes.Blog bItem, string[] strImgPathArray) { string tmpFile; string thmbNailPath; string userDir = ""; string strCat; strCat = @"blog"; //set userdir userDir = Session["userDir"].ToString(); //if panel is open check for loaded img files if (pnlAddImages.Visible) { //Collect files names, iterate through each and update accordingly HttpFileCollection uploadFilCol = System.Web.HttpContext.Current.Request.Files; int count = uploadFilCol.Count; //loop thru for each posted file for (int i = 0; i < count; i++) { //get handle to file HttpPostedFile file = uploadFilCol[i]; if (file.ContentLength > (int)0) { //get file name & ext string fileName = Path.GetFileName(file.FileName); string fileExt = Path.GetExtension(file.FileName).ToLower(); //Create dir if non-existent; We check the root here because BlogEdit lives within root/Blog/ if (!(Directory.Exists(Server.MapPath("/" + @"\users\" + userDir + strCat + @"\")))) { Directory.CreateDirectory(Server.MapPath("/" + @"\users\" + userDir + strCat + @"\")); } //get physical path to upload dir string path = Server.MapPath("/" + @"\users\" + userDir + strCat + @"\"); //Generate random file name tmpFile = GenerateRandomString(8).ToLower(); //concatenate renamed file with ext tmpFile = tmpFile + fileExt; //add together path and file name; This is our fully qualified *temp path where the file gets uploaded strImgPathArray[i] = Path.Combine(path, tmpFile); thmbNailPath = Path.Combine(path, "thmbNail_" + tmpFile); //Upload to temp dir; We'll write to perm directory after user confirms on preview! //FIXME: Check for file type and size if (fileName != string.Empty) { //resize the image and save //Create an image object from the uploaded file. try { System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(file.InputStream); //Larger Image variables int maxWidth = 300; int maxHeight = 300; int sourceWidth = UploadedImage.Width; int sourceHeight = UploadedImage.Height; int sourceX = 0; int sourceY = 0; int destX = 0; int destY = 0; float nPercent = 0; float nPercentW = 0; float nPercentH = 0; //ThumbNail variables int maxWidth_T = 150; int maxHeight_T = 150; int destX_T = 0; int destY_T = 0; float nPercent_T = 0; float nPercentW_T = 0; float nPercentH_T = 0; //Larger Image percents nPercentW = ((float)maxWidth / (float)sourceWidth); nPercentH = ((float)maxHeight / (float)sourceHeight); //Thumbnail percents nPercentW_T = ((float)maxWidth_T / (float)sourceWidth); nPercentH_T = ((float)maxHeight_T / (float)sourceHeight); //Find the biggest change(smallest pct) if (nPercentH < nPercentW) { //Larger Image Calculations nPercent = nPercentH; destX = System.Convert.ToInt16((maxWidth - (sourceWidth * nPercent)) / 2); //Thumbnail Calculations nPercent_T = nPercentH_T; destX_T = System.Convert.ToInt16((maxWidth_T - (sourceWidth * nPercent_T)) / 2); } else { //Larger Image Calculations nPercent = nPercentW; destY = System.Convert.ToInt16((maxHeight - (sourceHeight * nPercent)) / 2); //ThumbNail Calculations nPercent_T = nPercentW_T; destY_T = System.Convert.ToInt16((maxWidth_T - (sourceHeight * nPercent_T)) / 2); } //Larger Image Calculations int destWidth = (int)(sourceWidth * nPercent); int destHeight = (int)(sourceHeight * nPercent); //Smaller Image Calculations int destWidth_T = (int)(sourceWidth * nPercent_T); int destHeight_T = (int)(sourceHeight * nPercent_T); //create the larger bitmap Bitmap bmPhoto = new Bitmap(maxWidth, maxHeight); bmPhoto.SetResolution(UploadedImage.HorizontalResolution, UploadedImage.VerticalResolution); //create the thumbnail bitmap Bitmap bmPhotoThmbNail = new Bitmap(maxWidth_T, maxHeight_T); bmPhotoThmbNail.SetResolution(UploadedImage.HorizontalResolution, UploadedImage.VerticalResolution); //create larger graphic Graphics grPhoto = Graphics.FromImage(bmPhoto); grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; grPhoto.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; grPhoto.Clear(Color.Transparent); grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; grPhoto.DrawImage(UploadedImage, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel); //create thumbnail graphic Graphics grPhotoThmbNail = Graphics.FromImage(bmPhotoThmbNail); grPhotoThmbNail.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; grPhotoThmbNail.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; grPhotoThmbNail.Clear(Color.Transparent); grPhotoThmbNail.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; grPhotoThmbNail.DrawImage(UploadedImage, new Rectangle(destX_T, destY_T, destWidth_T, destHeight_T), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel); //int memberID = 0; //Save the Image(s) // (1) "Saves" the graphic. It really just updates the bitmap with the contents of the graphic. // Basically saving it in memory. // (2) Actually save the bitmap to the file system. //Larger grPhoto.Save(); // (1) bmPhoto.Save(strImgPathArray[i]); // (2) .., ImageFormat.Jpeg) //Thumbnail grPhotoThmbNail.Save(); bmPhotoThmbNail.Save(thmbNailPath); //strip out superfluous file path strImgPathArray[i] = Path.GetFileName(strImgPathArray[i]); //Find out who is set to "change" or "add" so we know who to update // - We call the clearSelection() to let ourselves know that index has been processed if (rdoImgMgr1.SelectedValue == "Change" || rdoImgMgr1.SelectedValue == "Add") { bItem.ImgPath1 = strImgPathArray[i]; rdoImgMgr1.ClearSelection(); } else if (rdoImgMgr2.SelectedValue == "Change" || rdoImgMgr2.SelectedValue == "Add") { bItem.ImgPath2 = strImgPathArray[i]; rdoImgMgr2.ClearSelection(); } } catch (Exception ex) { ErrorLog.ErrorRoutine(false, "Error: " + ex.Message); lblStatus.Text = "Upload/Save Error!"; } } //end if file > 0 } } //end for loop } return(bItem); }
/// <summary> /// Binds the search condition operator. /// </summary> /// <param name="saveSearchDoc">The save search doc.</param> /// <param name="saveSearchName">Name of the save search.</param> /// <param name="rdblSearchConditionList">The RDBL search condition list.</param> protected void BindSearchConditionOperator(XmlDocument saveSearchDoc, string saveSearchName, RadioButtonList rdblSearchConditionList) { if(saveSearchDoc != null) { XmlNode xmlNodeSaveSearch = saveSearchDoc.SelectSingleNode("saveSearchRequests/saveSearchRequest[@name='" + saveSearchName + "']"); XmlNode xmlNodeOperator = null; if(xmlNodeSaveSearch != null) { xmlNodeOperator = xmlNodeSaveSearch.SelectSingleNode("requestinfo/entity/attributegroup"); } if(xmlNodeOperator != null && xmlNodeOperator.Attributes["operator"] != null) { if(rdblSearchConditionList.Items.FindByText(xmlNodeOperator.Attributes["operator"].Value) != null) { rdblSearchConditionList.ClearSelection(); rdblSearchConditionList.Items.FindByText(xmlNodeOperator.Attributes["operator"].Value).Selected = true; } else if(rdblSearchConditionList.Items.FindByValue(xmlNodeOperator.Attributes["operator"].Value) != null) { rdblSearchConditionList.ClearSelection(); rdblSearchConditionList.Items.FindByValue(xmlNodeOperator.Attributes["operator"].Value).Selected = true; } } else { rdblSearchConditionList.SelectedIndex = 0; } } }