public static void DefaultButton(System.Web.UI.Page Page, ref System.Web.UI.WebControls.RadioButton radioButton, ref System.Web.UI.HtmlControls.HtmlInputButton inputButton) { try { System.Text.StringBuilder sScript = new System.Text.StringBuilder(); sScript.Append(Environment.NewLine + "<SCRIPT language=\"javascript\">" + Environment.NewLine); sScript.Append("function fnTrapKD(btn) {" + Environment.NewLine); sScript.Append(" if (document.all){" + Environment.NewLine); sScript.Append(" if (event.keyCode == 13)" + Environment.NewLine); sScript.Append(" { " + Environment.NewLine); sScript.Append(" event.returnValue=false;" + Environment.NewLine); sScript.Append(" event.cancel = true;" + Environment.NewLine); sScript.Append(" btn.click();" + Environment.NewLine); sScript.Append(" } " + Environment.NewLine); sScript.Append(" } " + Environment.NewLine); sScript.Append("}" + Environment.NewLine); sScript.Append("</SCRIPT>" + Environment.NewLine); radioButton.Attributes.Add("onkeydown", "try { fnTrapKD(document.all." + inputButton.ClientID + "); } catch (e) {}"); //Page.RegisterStartupScript("ForceDefaultToScript", sScript.ToString()); Page.ClientScript.RegisterStartupScript(Page.GetType(), "ForceDefaultToScript", sScript.ToString()); } catch (System.Exception ex) { UIManager.AdministrationManager.DiagnosticError(ex); } }
/// <summary> /// RadioButton控件翻译,从数据库中取值 /// </summary> /// <param name="button">要翻译的服务器控件</param> /// <param name="keyCode">字典键值</param> /// <param name="defaultText">默认值</param> public static void TranslationRadioButtonDB(System.Web.UI.WebControls.RadioButton radioButton, string keyCode, string defaultText) { string tlText = string.Empty; tlText = Translate(keyCode); if (tlText == "") { tlText = defaultText; } radioButton.Text = tlText; }
/// <summary> /// RadioButton 셋팅 /// </summary> /// <param name="objPage"></param> /// <param name="strPre"></param> /// <param name="nCount"></param> /// <param name="ReturnValue"></param> public static void SetRadioButton(System.Web.UI.Page objPage, string strPre, int nCount, string ReturnValue) { string strControlName; for (int nLoop = 1; nLoop <= nCount; nLoop++) { strControlName = strPre + nLoop.ToString(); System.Web.UI.WebControls.RadioButton objRadioButton = (System.Web.UI.WebControls.RadioButton)objPage.FindControl(strControlName); if (null != objRadioButton) { objRadioButton.Checked = (ReturnValue == nLoop.ToString()) ? true : false; } } }
/// <summary> /// 리디오 버턴 /// </summary> /// <param name="objPage"></param> /// <param name="strPre"></param> /// <param name="nCount"></param> /// <returns><returns> public static string GetRadioButton(System.Web.UI.Page objPage, string strPre, int nCount) { string strControlName; for (int nLoop = 1; nLoop <= nCount; nLoop++) { strControlName = strPre + nLoop.ToString(); System.Web.UI.WebControls.RadioButton objRadioButton = (System.Web.UI.WebControls.RadioButton)objPage.FindControl(strControlName); if (null != objRadioButton) { if (objRadioButton.Checked) { return(nLoop.ToString()); } } } return("0"); }
public void ClearForm(ControlCollection controls) { foreach (Control c in controls) { if (c.GetType() == typeof(System.Web.UI.WebControls.RadioButton)) { System.Web.UI.WebControls.RadioButton t = (System.Web.UI.WebControls.RadioButton)c; t.Checked = false; } if (c.GetType() == typeof(System.Web.UI.WebControls.Label)) { System.Web.UI.WebControls.Label l = (System.Web.UI.WebControls.Label)c; l.Text = String.Empty; } //... test for other controls in your forms DDL, checkboxes, etc. if (c.Controls.Count > 0) { ClearForm(c.Controls); } } }
/// <summary> /// Set back the updated value from the dataset to each controls of the panel /// Also sets validation and javascript events on the controls. /// </summary> /// <param name="PanelControls"></param> /// <param name="datasetDocument"></param> public void SetControlValues(System.Web.UI.WebControls.Panel PanelControls, DataSet datasetDocument) { try { System.Web.UI.WebControls.HiddenField HiddenFieldValidation = new System.Web.UI.WebControls.HiddenField(); using (datasetDocument) { HiddenFieldValidation.ID = "HiddenFieldValidation"; PanelControls.Controls.Add(HiddenFieldValidation); System.Collections.IEnumerator eControls = PanelControls.Controls.GetEnumerator(); while (eControls.MoveNext()) { object objCurrentControl = eControls.Current; switch (objCurrentControl.GetType().ToString()) { case "System.Web.UI.HtmlControls.HtmlInputHidden": { System.Web.UI.HtmlControls.HtmlInputHidden hdnTemp = (System.Web.UI.HtmlControls.HtmlInputHidden)objCurrentControl; string primaryKey = hdnTemp.Attributes["PrimaryKey"]; if (!String.IsNullOrEmpty(primaryKey)) { string fieldName = hdnTemp.Attributes["FieldName"]; string tableName = hdnTemp.Attributes["TableName"]; if (CheckFieldValues(tableName, fieldName, datasetDocument)) { hdnTemp.Value = datasetDocument.Tables[tableName].Rows[0][fieldName].ToString(); } } break; } case "System.Web.UI.WebControls.TextBox": { System.Web.UI.WebControls.TextBox txtTemp = (System.Web.UI.WebControls.TextBox)objCurrentControl; txtTemp.Attributes.Add("OnChange", "isdirty()"); string fieldName = txtTemp.Attributes["FieldName"]; string tableName = txtTemp.Attributes["TableName"]; string validation = txtTemp.Attributes["Validate"]; if (!String.IsNullOrEmpty(validation)) { if (HiddenFieldValidation.Value == "") { HiddenFieldValidation.Value = txtTemp.ClientID; } else { HiddenFieldValidation.Value += ";" + txtTemp.ClientID; } } if (CheckFieldValues(tableName, fieldName, datasetDocument)) { txtTemp.Text = datasetDocument.Tables[tableName].Rows[0][fieldName].ToString(); } break; } case "System.Web.UI.WebControls.CheckBox": { System.Web.UI.WebControls.CheckBox chkTemp = (System.Web.UI.WebControls.CheckBox)objCurrentControl; chkTemp.Attributes.Add("OnClick", "isdirty()"); string fieldName = chkTemp.Attributes["FieldName"]; string tableName = chkTemp.Attributes["TableName"]; string validation = chkTemp.Attributes["Validate"]; if (!String.IsNullOrEmpty(validation)) { if (HiddenFieldValidation.Value == "") { HiddenFieldValidation.Value = chkTemp.ClientID; } else { HiddenFieldValidation.Value += ";" + chkTemp.ClientID; } } if (CheckFieldValues(tableName, fieldName, datasetDocument)) { chkTemp.Checked = datasetDocument.Tables[tableName].Rows[0][fieldName].ToString() == "Y" ? true : false; } break; } case "System.Web.UI.WebControls.DropDownList": { System.Web.UI.WebControls.DropDownList ddlTemp = (System.Web.UI.WebControls.DropDownList)objCurrentControl; ddlTemp.Attributes.Add("OnChange", "isdirty()"); string fieldName = ddlTemp.Attributes["FieldName"]; string tableName = ddlTemp.Attributes["TableName"]; string dataSource = ddlTemp.Attributes["DataSource"]; /////////No Need string SelectCase = ddlTemp.Attributes["SelectCase"]; string SelectType = ddlTemp.Attributes["SelectType"]; string dataTextField = ddlTemp.Attributes["TextField"]; string dataValueField = ddlTemp.Attributes["ValueField"]; string validation = ddlTemp.Attributes["Validate"]; if (!String.IsNullOrEmpty(validation)) { if (HiddenFieldValidation.Value == "") { HiddenFieldValidation.Value = ddlTemp.ClientID; } else { HiddenFieldValidation.Value += ";" + ddlTemp.ClientID; } } //FillDropDowns(ddlTemp, dataSource, dataTextField, dataValueField); FillDropDowns(ddlTemp, dataSource, dataTextField, dataValueField, SelectCase, SelectType); if (CheckFieldValues(tableName, fieldName, datasetDocument)) { ddlTemp.SelectedValue = datasetDocument.Tables[tableName].Rows[0][fieldName].ToString(); } break; } case "System.Web.UI.WebControls.RadioButton": { System.Web.UI.WebControls.RadioButton rbTemp = (System.Web.UI.WebControls.RadioButton)objCurrentControl; rbTemp.Attributes.Add("OnClick", "isdirty()"); string fieldName = rbTemp.Attributes["FieldName"]; string tableName = rbTemp.Attributes["TableName"]; string value = rbTemp.Attributes["Value"]; string validation = rbTemp.Attributes["Validate"]; if (!String.IsNullOrEmpty(validation)) { if (HiddenFieldValidation.Value == "") { HiddenFieldValidation.Value = rbTemp.ClientID; } else { HiddenFieldValidation.Value += ";" + rbTemp.ClientID; } } if (CheckFieldValues(tableName, fieldName, datasetDocument)) { if (datasetDocument.Tables[tableName].Rows[0][fieldName].ToString().Trim() == value.Trim()) { rbTemp.Checked = true; } } break; } } } } } catch (Exception ex) { throw (ex); } }
/// <summary> /// Creates datarows pertaining to the controls in the panel and updates them /// </summary> /// <param name="PanelControls">Panel with contains the collection </param> /// <param name="objTemp">Object which contains values regarding the documentrow</param> /// <returns>true on successful update</returns> public bool UpdateData(System.Web.UI.WebControls.Panel PanelControls, ref object objTemp) { try { objCommonBase = new Streamline.DataService.CommonBase(); System.Collections.Hashtable hashTableTemp = (System.Collections.Hashtable)objTemp; string dataFileTemp = PanelControls.Attributes["DataFile"]; string dataFileAfterUpdate = PanelControls.Attributes["DataFileAfterUpdate"]; //This statement is used to get the collections of controls in the panel. //GetEnumerator is a forward only and light weight cursor.Hence it is more efficient than // For each control in Panel. System.Collections.IEnumerator eControls = PanelControls.Controls.GetEnumerator(); datasetMain = new DataSet(); if (!String.IsNullOrEmpty(dataFileAfterUpdate)) { datasetMain.ReadXml(PATH + System.Web.HttpContext.Current.Session.SessionID + "\\" + dataFileAfterUpdate, XmlReadMode.ReadSchema); datasetMain.AcceptChanges(); } else { datasetMain.ReadXmlSchema(PATH + dataFileTemp); } newRow = true; //if(hashTableTemp.ContainsKey("DocumentId")) // AddDataRowValues(tableName, fieldName, hdnTemp.Value, primaryKey == "True" ? true : false); //if(hashTableTemp.ContainsKey("Version")) // AddDataRowValues(tableName, fieldName, hdnTemp.Value, primaryKey == "True" ? true : false); while (eControls.MoveNext()) { object objCurrentControl = eControls.Current; switch (objCurrentControl.GetType().ToString()) { case "System.Web.UI.HtmlControls.HtmlInputHidden": { System.Web.UI.HtmlControls.HtmlInputHidden hdnTemp = (System.Web.UI.HtmlControls.HtmlInputHidden)objCurrentControl; string primaryKey = hdnTemp.Attributes["PrimaryKey"]; if (!String.IsNullOrEmpty(primaryKey)) { string fieldName = hdnTemp.Attributes["FieldName"]; string tableName = hdnTemp.Attributes["TableName"]; if (primaryKey == "True") { if (String.IsNullOrEmpty(hdnTemp.Value)) { if (hashTableTemp.ContainsKey(fieldName)) { hdnTemp.Value = hashTableTemp[fieldName].ToString(); } } else { newRow = false; } AddDataRowValues(tableName, fieldName, hdnTemp.Value, primaryKey == "True" ? true : false); } } break; } case "System.Web.UI.WebControls.TextBox": { System.Web.UI.WebControls.TextBox txtTemp = (System.Web.UI.WebControls.TextBox)objCurrentControl; string fieldName = txtTemp.Attributes["FieldName"]; string tableName = txtTemp.Attributes["TableName"]; AddDataRowValues(tableName, fieldName, txtTemp.Text, false); break; } case "System.Web.UI.WebControls.CheckBox": { System.Web.UI.WebControls.CheckBox chkTemp = (System.Web.UI.WebControls.CheckBox)objCurrentControl; string fieldName = chkTemp.Attributes["FieldName"]; string tableName = chkTemp.Attributes["TableName"]; AddDataRowValues(tableName, fieldName, chkTemp.Checked == true ? "Y" : "N", false); break; } case "System.Web.UI.WebControls.DropDownList": { System.Web.UI.WebControls.DropDownList ddlTemp = (System.Web.UI.WebControls.DropDownList)objCurrentControl; string fieldName = ddlTemp.Attributes["FieldName"]; string tableName = ddlTemp.Attributes["TableName"]; AddDataRowValues(tableName, fieldName, ddlTemp.SelectedValue, false); break; } case "System.Web.UI.WebControls.RadioButton": { System.Web.UI.WebControls.RadioButton rbTemp = (System.Web.UI.WebControls.RadioButton)objCurrentControl; string fieldName = rbTemp.Attributes["FieldName"]; string tableName = rbTemp.Attributes["TableName"]; string value = rbTemp.Attributes["Value"]; if (rbTemp.Checked == true) { AddDataRowValues(tableName, fieldName, value, false); } break; } } } //Merging the documents table to the maindataset datasetMain.Merge(getDocumentTable(objTemp)); DataSet dsUpdated = objCommonBase.UpdateDocuments(datasetMain); string updateFile = System.Guid.NewGuid().ToString() + ".xml"; dsUpdated.WriteXml(PATH + System.Web.HttpContext.Current.Session.SessionID + "\\" + updateFile, XmlWriteMode.WriteSchema); PanelControls.Attributes["DataFileAfterUpdate"] = updateFile; // setting back the updated documentid and version id to the arguments passed by the parent class if (dsUpdated.Tables.Count > 0) { if (dsUpdated.Tables[0].Columns.Contains("DocumentId")) { if (dsUpdated.Tables[0].Rows.Count > 0) { if (hashTableTemp.ContainsKey("DocumentId")) { hashTableTemp["DocumentId"] = Convert.ToInt32(dsUpdated.Tables[0].Rows[0]["DocumentId"]); } else { hashTableTemp.Add("DocumentId", Convert.ToInt32(dsUpdated.Tables[0].Rows[0]["DocumentId"])); } if (hashTableTemp.ContainsKey("Version")) { hashTableTemp["Version"] = Convert.ToInt32(dsUpdated.Tables[0].Rows[0]["Version"]); } else { hashTableTemp.Add("Version", Convert.ToInt32(dsUpdated.Tables[0].Rows[0]["Version"])); } } } } // SetControlValues(PanelControls, dsUpdated); return(true); } catch (Exception ex) { return(false); } }
public static int IndexGVRadioButton(object sender) { System.Web.UI.WebControls.RadioButton ct = (System.Web.UI.WebControls.RadioButton)sender; System.Web.UI.WebControls.GridViewRow gvRow = (System.Web.UI.WebControls.GridViewRow)ct.NamingContainer; return(gvRow.RowIndex); }
/// <summary> /// 服务器控件的翻译,从数据库中取值 /// </summary> /// <param name="control">要翻译的控件</param> /// <param name="items">二维数组型参数,第二维第一个为字典键值,第二个为默认值</param> public void TranControlsDB(object control, string[][] items) { switch (control.GetType().ToString()) // { case "System.Web.UI.WebControls.GridView": System.Web.UI.WebControls.GridView gv = (System.Web.UI.WebControls.GridView)control; Translation.TranslationGridViewDB(gv, items); break; case "System.Web.UI.WebControls.DataGrid": System.Web.UI.WebControls.DataGrid dg = (System.Web.UI.WebControls.DataGrid)control; Translation.TranslationDataGridDB(dg, items); break; case "System.Web.UI.WebControls.RadioButtonList": System.Web.UI.WebControls.RadioButtonList rbl = (System.Web.UI.WebControls.RadioButtonList)control; Translation.TranslationRadioButtonListDB(rbl, items); break; case "System.Web.UI.WebControls.DropDownList": System.Web.UI.WebControls.DropDownList ddl = (System.Web.UI.WebControls.DropDownList)control; Translation.TranslationDropDownListDB(ddl, items); break; case "System.Web.UI.WebControls.CheckBoxList": System.Web.UI.WebControls.CheckBoxList chkl = (System.Web.UI.WebControls.CheckBoxList)control; Translation.TranslationCheckBoxListDB(chkl, items); break; case "System.Web.UI.WebControls.Button": System.Web.UI.WebControls.Button button = (System.Web.UI.WebControls.Button)control; Translation.TranslationButtonDB(button, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.LinkButton": System.Web.UI.WebControls.LinkButton lbtn = (System.Web.UI.WebControls.LinkButton)control; Translation.TranslationLinkButtonDB(lbtn, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.ImageButton": System.Web.UI.WebControls.ImageButton imgBtn = (System.Web.UI.WebControls.ImageButton)control; Translation.TranslationImageButtonDB(imgBtn, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.HyperLink": System.Web.UI.WebControls.HyperLink hl = (System.Web.UI.WebControls.HyperLink)control; Translation.TranslationHyperLinkDB(hl, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.Label": System.Web.UI.WebControls.Label label = (System.Web.UI.WebControls.Label)control; Translation.TranslationLabelDB(label, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.CheckBox": System.Web.UI.WebControls.CheckBox chk = (System.Web.UI.WebControls.CheckBox)control; Translation.TranslationCheckBoxDB(chk, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.RadioButton": System.Web.UI.WebControls.RadioButton rbtn = (System.Web.UI.WebControls.RadioButton)control; Translation.TranslationRadioButtonDB(rbtn, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.RequiredFieldValidator": System.Web.UI.WebControls.RequiredFieldValidator rfv = (System.Web.UI.WebControls.RequiredFieldValidator)control; Translation.TranslationRequiredFieldValidatorDB(rfv, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.RangeValidator": System.Web.UI.WebControls.RangeValidator rv = (System.Web.UI.WebControls.RangeValidator)control; Translation.TranslationRangeValidatorDB(rv, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.CompareValidator": System.Web.UI.WebControls.CompareValidator cv = (System.Web.UI.WebControls.CompareValidator)control; Translation.TranslationCompareValidatorDB(cv, items[0][0], items[0][1]); break; case "System.Web.UI.WebControls.RegularExpressionValidator": System.Web.UI.WebControls.RegularExpressionValidator rev = (System.Web.UI.WebControls.RegularExpressionValidator)control; Translation.TranslationRegularExpressionValidatorDB(rev, items[0][0], items[0][1]); break; } }
public virtual new void RegisterRadioButton(System.Web.UI.WebControls.RadioButton radioButton) { Contract.Requires(radioButton != null); }
public virtual void RegisterRadioButton(System.Web.UI.WebControls.RadioButton radioButton) { }
/// <summary> /// 清理表单 /// </summary> /// <param name="control"></param> public static void ClearForm(WebUI.Control control) { if (control == null) { return; } foreach (WebUI.Control ctl in control.Controls) { Type type = ctl.GetType(); #region 处理服务器控件 if (type == typeof(WebUI.WebControls.TextBox))//文本框 { WebUI.WebControls.TextBox box = ((WebUI.WebControls.TextBox)ctl); box.Text = ""; if (box.Attributes["isNumber"] != null) { box.Text = "0"; } } else if (type == typeof(WebUI.WebControls.DropDownList))//选择框 { ((WebUI.WebControls.DropDownList)ctl).SelectedIndex = -1; } else if (type == typeof(WebUI.WebControls.HiddenField))//隐藏域 { ((WebUI.WebControls.HiddenField)ctl).Value = ""; } else if (type == typeof(WebUI.WebControls.RadioButton))//单选框 { WebUI.WebControls.RadioButton rb = (WebUI.WebControls.RadioButton)ctl; rb.Checked = false; } else if (type == typeof(WebUI.WebControls.CheckBox))//复选框 { WebUI.WebControls.CheckBox ck = (WebUI.WebControls.CheckBox)ctl; ck.Checked = false; } else if (type == typeof(WebUI.WebControls.CheckBoxList))//复选框列表 { WebUI.WebControls.CheckBoxList ck = (WebUI.WebControls.CheckBoxList)ctl; foreach (WebUI.WebControls.ListItem li in ck.Items) { li.Selected = false; } } else if (type == typeof(WebUI.WebControls.RadioButtonList))//单框列表 { WebUI.WebControls.RadioButtonList ck = (WebUI.WebControls.RadioButtonList)ctl; foreach (WebUI.WebControls.ListItem li in ck.Items) { li.Selected = false; } } else if (type == typeof(WebUI.WebControls.ListBox))//列表框 { WebUI.WebControls.ListBox ck = (WebUI.WebControls.ListBox)ctl; foreach (WebUI.WebControls.ListItem li in ck.Items) { li.Selected = false; } } #endregion #region 处理不同Html控件 else if (type == typeof(WebUI.HtmlControls.HtmlInputText))//文本域 { WebUI.HtmlControls.HtmlInputText ct = (WebUI.HtmlControls.HtmlInputText)ctl; ct.Value = ""; if (ct.Attributes["isNumber"] != null) { ct.Value = "0"; } } else if (type == typeof(WebUI.HtmlControls.HtmlTextArea))//文本域 { WebUI.HtmlControls.HtmlTextArea ct = (WebUI.HtmlControls.HtmlTextArea)ctl; ct.Value = ""; } else if (type == typeof(WebUI.HtmlControls.HtmlSelect))//选择域 { WebUI.HtmlControls.HtmlSelect ct = (WebUI.HtmlControls.HtmlSelect)ctl; ct.SelectedIndex = -1; } else if (type == typeof(WebUI.HtmlControls.HtmlInputHidden))////隐藏域 { WebUI.HtmlControls.HtmlInputHidden ct = (WebUI.HtmlControls.HtmlInputHidden)ctl; ct.Value = ""; if (ct.Attributes["isNumber"] != null) { ct.Value = "0"; } } else if (type == typeof(WebUI.HtmlControls.HtmlInputRadioButton))//单选域 { WebUI.HtmlControls.HtmlInputRadioButton rb = (WebUI.HtmlControls.HtmlInputRadioButton)ctl; rb.Checked = false; } else if (type == typeof(WebUI.HtmlControls.HtmlInputCheckBox))//复选域 { WebUI.HtmlControls.HtmlInputCheckBox ck = (WebUI.HtmlControls.HtmlInputCheckBox)ctl; ck.Checked = false; } else if (type == typeof(WebUI.HtmlControls.HtmlInputPassword))//密码域 { WebUI.HtmlControls.HtmlInputPassword ck = (WebUI.HtmlControls.HtmlInputPassword)ctl; ck.Value = ""; } #endregion } }
/// <summary> /// 填充model /// </summary> /// <param name="entity"></param> /// <param name="control"></param> public static void FillModel(Object entity, WebUI.Control control) { if (entity == null || control == null) { return; } NameValueCollection formData = HttpContext.Current.Request.Form; PropertyInfo[] propertyList = entity.GetProperties(); foreach (PropertyInfo pi in propertyList) { string ctlId = string.Format(IdFormat, pi.Name); WebUI.Control ctl = control.FindControl(ctlId); if (ctl == null) { #region 处理HMTL标签 if (formData[ctlId] != null) { entity.SetPropertyValue(pi.Name, formData[ctlId]); } #endregion continue; } Type ctlType = ctl.GetType(); #region 处理服务器控件 if (ctlType == typeof(WebUI.WebControls.TextBox))//文本框 { entity.SetPropertyValue(pi.Name, ((WebUI.WebControls.TextBox)ctl).Text); } else if (ctlType == typeof(WebUI.WebControls.Image))//图片 { entity.SetPropertyValue(pi.Name, ((WebUI.WebControls.Image)ctl).ImageUrl); } else if (ctlType == typeof(WebUI.WebControls.DropDownList))//选择框 { entity.SetPropertyValue(pi.Name, ((WebUI.WebControls.DropDownList)ctl).SelectedValue); } else if (ctlType == typeof(WebUI.WebControls.HiddenField))//隐藏域 { entity.SetPropertyValue(pi.Name, ((WebUI.WebControls.HiddenField)ctl).Value); } else if (ctlType == typeof(WebUI.WebControls.RadioButton))//单选框 { WebUI.WebControls.RadioButton rb = (WebUI.WebControls.RadioButton)ctl; if (rb.Checked) { entity.SetPropertyValue(pi.Name, rb.Text); } else { entity.SetPropertyValue(pi.Name, ""); } } else if (ctlType == typeof(WebUI.WebControls.CheckBox))//复选框 { WebUI.WebControls.CheckBox ck = (WebUI.WebControls.CheckBox)ctl; if (ck.Checked) { entity.SetPropertyValue(pi.Name, ck.Text); } else { entity.SetPropertyValue(pi.Name, ""); } } else if (ctlType == typeof(WebUI.WebControls.CheckBoxList))//复选框列表 { WebUI.WebControls.CheckBoxList ck = (WebUI.WebControls.CheckBoxList)ctl; string rs = ""; foreach (WebUI.WebControls.ListItem li in ck.Items) { if (li.Selected) { rs += "," + li.Value; } } if (rs.Length > 1) { rs = rs.Substring(1); } entity.SetPropertyValue(pi.Name, rs); } else if (ctlType == typeof(WebUI.WebControls.RadioButtonList))//单框列表 { WebUI.WebControls.RadioButtonList ck = (WebUI.WebControls.RadioButtonList)ctl; entity.SetPropertyValue(pi.Name, ck.SelectedValue); } else if (ctlType == typeof(WebUI.WebControls.ListBox))//列表框 { WebUI.WebControls.ListBox ck = (WebUI.WebControls.ListBox)ctl; string rs = ""; foreach (WebUI.WebControls.ListItem li in ck.Items) { if (li.Selected) { rs += "," + li.Value; } } if (rs.Length > 1) { rs = rs.Substring(1); } entity.SetPropertyValue(pi.Name, rs); } #endregion #region 处理不同Html控件 else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputText))//文本域 { WebUI.HtmlControls.HtmlInputText ct = (WebUI.HtmlControls.HtmlInputText)ctl; entity.SetPropertyValue(pi.Name, ct.Value); } else if (ctlType == typeof(WebUI.HtmlControls.HtmlTextArea))//文本域 { WebUI.HtmlControls.HtmlTextArea ct = (WebUI.HtmlControls.HtmlTextArea)ctl; entity.SetPropertyValue(pi.Name, ct.Value); } else if (ctlType == typeof(WebUI.HtmlControls.HtmlSelect))//选择域 { WebUI.HtmlControls.HtmlSelect ct = (WebUI.HtmlControls.HtmlSelect)ctl; entity.SetPropertyValue(pi.Name, ct.Items[ct.SelectedIndex].Value); } else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputHidden))////隐藏域 { WebUI.HtmlControls.HtmlInputHidden ct = (WebUI.HtmlControls.HtmlInputHidden)ctl; entity.SetPropertyValue(pi.Name, ct.Value); } else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputRadioButton))//单选域 { WebUI.HtmlControls.HtmlInputRadioButton rb = (WebUI.HtmlControls.HtmlInputRadioButton)ctl; if (rb.Checked) { entity.SetPropertyValue(pi.Name, rb.Value); } } else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputCheckBox))//复选域 { WebUI.HtmlControls.HtmlInputCheckBox ck = (WebUI.HtmlControls.HtmlInputCheckBox)ctl; if (ck.Checked) { entity.SetPropertyValue(pi.Name, ck.Value); } } else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputPassword))//密码域 { WebUI.HtmlControls.HtmlInputPassword ck = (WebUI.HtmlControls.HtmlInputPassword)ctl; entity.SetPropertyValue(pi.Name, ck.Value); } #endregion } }
/// <summary> /// 填充表单 /// </summary> /// <param name="entity"></param> /// <param name="control"></param> public static void FillForm(WebUI.Control control, Object entity) { if (entity == null || control == null) { return; } PropertyInfo[] propertyList = entity.GetProperties(); foreach (PropertyInfo pi in propertyList) { WebUI.Control ctl = control.FindControl(string.Format(IdFormat, pi.Name)); if (ctl == null) { continue; } Type ctlType = ctl.GetType(); #region 处理服务器控件 if (ctlType == typeof(WebUI.WebControls.TextBox))//文本框 { if (entity.GetPropertyValue(pi.Name) != null) { ((WebUI.WebControls.TextBox)ctl).Text = entity.GetPropertyValue(pi.Name).ToString(); } } else if (ctlType == typeof(WebUI.WebControls.Image))//图片 { if (entity.GetPropertyValue(pi.Name) != null) { string imageUrl = entity.GetPropertyValue(pi.Name).ToString(); if (!string.IsNullOrEmpty(imageUrl)) { ((WebUI.WebControls.Image)ctl).ImageUrl = imageUrl; } } } else if (ctlType == typeof(WebUI.WebControls.DropDownList))//选择框 { if (entity.GetPropertyValue(pi.Name) != null) { ((WebUI.WebControls.DropDownList)ctl).SelectedValue = entity.GetPropertyValue(pi.Name).ToString(); } } else if (ctlType == typeof(WebUI.WebControls.HiddenField))//隐藏域 { if (entity.GetPropertyValue(pi.Name) != null) { ((WebUI.WebControls.HiddenField)ctl).Value = entity.GetPropertyValue(pi.Name).ToString(); } } else if (ctlType == typeof(WebUI.WebControls.RadioButton))//单选框 { WebUI.WebControls.RadioButton rb = (WebUI.WebControls.RadioButton)ctl; if (entity.GetPropertyValue(pi.Name) != null) { rb.Checked = entity.GetPropertyValue(pi.Name).ToString() == rb.Text ? true : false; } } else if (ctlType == typeof(WebUI.WebControls.CheckBox))//复选框 { WebUI.WebControls.CheckBox ck = (WebUI.WebControls.CheckBox)ctl; if (entity.GetPropertyValue(pi.Name) != null) { ck.Checked = entity.GetPropertyValue(pi.Name).ToString() == ck.Text ? true : false; } } else if (ctlType == typeof(WebUI.WebControls.CheckBoxList))//复选框列表 { WebUI.WebControls.CheckBoxList ck = (WebUI.WebControls.CheckBoxList)ctl; if (entity.GetPropertyValue(pi.Name) != null) { string sel = entity.GetPropertyValue(pi.Name).ToString(); foreach (WebUI.WebControls.ListItem li in ck.Items) { if (sel.IndexOf(",") > -1 && (sel.IndexOf(li.Value + ",") > -1 || sel.IndexOf("," + li.Value) > -1)) { li.Selected = true; } else if (sel.IndexOf(",") == -1 && sel == li.Value) { li.Selected = true; } else { li.Selected = false; } } } } else if (ctlType == typeof(WebUI.WebControls.RadioButtonList))//单框列表 { WebUI.WebControls.RadioButtonList ck = (WebUI.WebControls.RadioButtonList)ctl; if (entity.GetPropertyValue(pi.Name) != null) { ck.SelectedValue = entity.GetPropertyValue(pi.Name).ToString(); } } else if (ctlType == typeof(WebUI.WebControls.ListBox))//列表框 { WebUI.WebControls.ListBox ck = (WebUI.WebControls.ListBox)ctl; if (entity.GetPropertyValue(pi.Name) != null) { string sel = entity.GetPropertyValue(pi.Name).ToString(); foreach (WebUI.WebControls.ListItem li in ck.Items) { if (sel.IndexOf(",") > -1 && (sel.IndexOf(li.Value + ",") > -1 || sel.IndexOf("," + li.Value) > -1)) { li.Selected = true; } else if (sel.IndexOf(",") == -1 && sel == li.Value) { li.Selected = true; } else { li.Selected = false; } } } } #endregion #region 处理不同Html控件 else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputText))//文本域 { WebUI.HtmlControls.HtmlInputText ct = (WebUI.HtmlControls.HtmlInputText)ctl; if (entity.GetPropertyValue(pi.Name) != null) { ct.Value = entity.GetPropertyValue(pi.Name).ToString(); } } else if (ctlType == typeof(WebUI.HtmlControls.HtmlTextArea))//文本域 { WebUI.HtmlControls.HtmlTextArea ct = (WebUI.HtmlControls.HtmlTextArea)ctl; if (entity.GetPropertyValue(pi.Name) != null) { ct.Value = entity.GetPropertyValue(pi.Name).ToString(); } } else if (ctlType == typeof(WebUI.HtmlControls.HtmlSelect))//选择域 { WebUI.HtmlControls.HtmlSelect ct = (WebUI.HtmlControls.HtmlSelect)ctl; if (entity.GetPropertyValue(pi.Name) != null) { for (int i = 0; i < ct.Items.Count; i++) { if (ct.Items[i].Value == entity.GetPropertyValue(pi.Name).ToString()) { ct.SelectedIndex = i; } } } } else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputHidden))////隐藏域 { WebUI.HtmlControls.HtmlInputHidden ct = (WebUI.HtmlControls.HtmlInputHidden)ctl; if (entity.GetPropertyValue(pi.Name) != null) { ct.Value = entity.GetPropertyValue(pi.Name).ToString(); } } else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputRadioButton))//单选域 { WebUI.HtmlControls.HtmlInputRadioButton rb = (WebUI.HtmlControls.HtmlInputRadioButton)ctl; if (rb.Checked && entity.GetPropertyValue(pi.Name) != null) { rb.Checked = entity.GetPropertyValue(pi.Name).ToString() == rb.Value ? true : false; } } else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputCheckBox))//复选域 { WebUI.HtmlControls.HtmlInputCheckBox ck = (WebUI.HtmlControls.HtmlInputCheckBox)ctl; if (entity.GetPropertyValue(pi.Name) != null) { if (entity.GetPropertyValue(pi.Name).ToString().IndexOf("," + ck.Value) != -1) { ck.Checked = true; } } } else if (ctlType == typeof(WebUI.HtmlControls.HtmlInputPassword))//密码域 { WebUI.HtmlControls.HtmlInputPassword ck = (WebUI.HtmlControls.HtmlInputPassword)ctl; if (entity.GetPropertyValue(pi.Name) != null) { ck.Value = entity.GetPropertyValue(pi.Name).ToString(); } } #endregion } }