Ejemplo n.º 1
0
 /// <summary>
 /// 单选框数据加载
 /// </summary>
 /// <param name="DDL_Items"></param>
 /// <param name="tablename">表名</param>
 /// <param name="mtext">名称字段</param>
 /// <param name="mvalue">编号字段</param>
 public static void LoadSelection(ref System.Web.UI.WebControls.RadioButtonList DDL_Items, string tablename, string mtext, string mvalue)
 {
     DDL_Items.DataSource = GetSelections(tablename);
     DDL_Items.Items.Clear();
     DDL_Items.SelectedIndex  = -1;
     DDL_Items.DataTextField  = mtext;
     DDL_Items.DataValueField = mvalue;
     DDL_Items.DataBind();
 }
Ejemplo n.º 2
0
        public void ViewExamPaper(string vStudentId, string vModuleId, string vAttempt, System.Web.UI.WebControls.Panel panelDataView)
        {
            try
            {
                DatabaseConnection DB = new DatabaseConnection();
                DB.openConnection();

                string         sqlSelectCmd = "SELECT t1.providedAnswer, t2.question, t2.answer01, t2.answer02, t2.answer03, t2.answer04, t2.correctAnswer FROM StudentAnswer AS t1 LEFT JOIN Questions AS t2 ON t1.answeredQuestionId = t2.questionId WHERE answeredStudentId = '" + vStudentId + "' AND answerModuleId = '" + vModuleId + "' AND questionAttempt = '" + vAttempt + "'";
                SqlDataAdapter dataAdapter  = new SqlDataAdapter(sqlSelectCmd, DatabaseConnection.dbConnection);
                DataSet        DSet         = new DataSet();
                dataAdapter.Fill(DSet);
                DB.closeConnection();
                int number = 0;

                foreach (DataTable DT in DSet.Tables)
                {
                    foreach (DataRow row in DT.Rows)
                    {
                        System.Web.UI.WebControls.Label lblQuestion = new System.Web.UI.WebControls.Label();
                        lblQuestion.Text = row[1].ToString();

                        System.Web.UI.WebControls.RadioButtonList rbListQuestion = new System.Web.UI.WebControls.RadioButtonList();
                        rbListQuestion.Items.Add(row[2].ToString());
                        rbListQuestion.Items.Add(row[3].ToString());
                        rbListQuestion.Items.Add(row[4].ToString());
                        rbListQuestion.Items.Add(row[5].ToString());
                        rbListQuestion.SelectedIndex = Convert.ToInt32(row[0]) - 1;
                        if (row[0].ToString() != row[6].ToString())
                        {
                            rbListQuestion.SelectedItem.Attributes.Add("style", "color: red");
                        }
                        else
                        {
                            rbListQuestion.SelectedItem.Attributes.Add("style", "color: green");
                        }

                        System.Web.UI.WebControls.Label lbl = new System.Web.UI.WebControls.Label();
                        lbl.Text = ((number + 1) + ". ").ToString();
                        number++;

                        System.Web.UI.WebControls.Label label = new System.Web.UI.WebControls.Label();
                        label.Text = "";

                        panelDataView.Controls.Add(lbl);
                        panelDataView.Controls.Add(lblQuestion);
                        panelDataView.Controls.Add(rbListQuestion);
                        panelDataView.Controls.Add(new LiteralControl("<br />"));
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error" + e);
            }
        }
Ejemplo n.º 3
0
 public static void BindRadioButtonList(ref System.Web.UI.WebControls.RadioButtonList rdControl, DataTable dt, string DataTextField, string DataValueField, string SelectedValue)
 {
     rdControl.DataTextField  = DataTextField;
     rdControl.DataValueField = DataValueField;
     rdControl.DataSource     = dt;
     rdControl.DataBind();
     if (SelectedValue != String.Empty)
     {
         rdControl.SelectedValue = SelectedValue;
     }
 }
Ejemplo n.º 4
0
 public static bool SafeSelect(ref System.Web.UI.WebControls.RadioButtonList objList, string strValue)
 {
     foreach (System.Web.UI.WebControls.ListItem objItem in objList.Items)
     {
         if (objItem.Value == strValue)
         {
             objItem.Selected      = true;
             objList.SelectedValue = strValue;
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// RadioButtonList控件翻译,从数据库中取值
        /// </summary>
        /// <param name="button">要翻译的服务器控件</param>
        /// <param name="columns">二维数组型参数,第二维第一个为字典键值,第二个为默认值</param>
        public static void TranslationRadioButtonListDB(System.Web.UI.WebControls.RadioButtonList rbl, string[][] items)
        {
            string tlText = string.Empty;

            for (int i = 0; i < items.Length; i++)
            {
                tlText = Translate(items[i][0]);
                if (tlText == "")
                {
                    tlText = items[i][1];
                }
                rbl.Items[i].Text = tlText;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Sets a Selected Item of a RadioButtonList Server Control according to value
 /// </summary>
 /// <param name="ddl"></param>
 /// <param name="selectedValue"></param>
 public static void SetSelectedItem(this System.Web.UI.WebControls.RadioButtonList rdbl, String selectedValue)
 {
     if (rdbl != null && rdbl.Items.Count > 0)
     {
         rdbl.ClearSelection();
         foreach (System.Web.UI.WebControls.ListItem item in rdbl.Items)
         {
             if (String.Compare(item.Value, selectedValue, true) == 0)
             {
                 item.Selected = true;
                 break;
             }
         }
     }
 }
Ejemplo n.º 7
0
 public void LoadExamQuestions(System.Web.UI.WebControls.Label lblQuestion, System.Web.UI.WebControls.RadioButtonList rbListQuestion, int pageIndex, System.Web.UI.WebControls.HiddenField hiddenField, System.Web.UI.WebControls.HiddenField hfCorrectAns)
 {
     try
     {
         hiddenField.Value = DS.Tables[0].Rows[pageIndex][0].ToString();
         lblQuestion.Text  = DS.Tables[0].Rows[pageIndex][1].ToString();
         rbListQuestion.Items.Add(DS.Tables[0].Rows[pageIndex][2].ToString());
         rbListQuestion.Items.Add(DS.Tables[0].Rows[pageIndex][3].ToString());
         rbListQuestion.Items.Add(DS.Tables[0].Rows[pageIndex][4].ToString());
         rbListQuestion.Items.Add(DS.Tables[0].Rows[pageIndex][5].ToString());
         hfCorrectAns.Value = DS.Tables[0].Rows[pageIndex][6].ToString();
     }
     catch (Exception e)
     {
         MessageBox.Show("Error" + e);
     }
 }
Ejemplo n.º 8
0
 public static void selectRadioButtonList(System.Web.UI.WebControls.RadioButtonList rblList, string code)
 {
     if (code == null || rblList == null)
     {
         return;
     }
     System.Web.UI.WebControls.ListItem crItem = null;
     crItem = rblList.Items.FindByValue(code);
     if (crItem != null)
     {
         rblList.SelectedValue = code;
     }
     else
     {
         rblList.SelectedIndex = 0;
     }
     return;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 根据值设定单选框选中项
 /// </summary>
 /// <param name="RB_Items">单选框</param>
 /// <param name="Value">值</param>
 public static void SetIndex(ref System.Web.UI.WebControls.RadioButtonList RB_Items, string Value)
 {
     if (RB_Items.SelectedIndex > 0)
     {
         RB_Items.Items[RB_Items.SelectedIndex].Selected = false;
     }
     if (Value.Trim() == "")
     {
         RB_Items.Items[0].Selected = true;
     }
     else
     {
         for (int i = 0; i < RB_Items.Items.Count; i++)
         {
             if (RB_Items.Items[i].Value.Trim() == Value.Trim())
             {
                 RB_Items.Items[i].Selected = true;
                 break;
             }
         }
     }
 }
Ejemplo n.º 10
0
 public void cargarAreaTerapeutica_RadioButtonList(ref System.Web.UI.WebControls.RadioButtonList radiobuttonlist)
 {
     Controles.LlenarRadioButtonList(ref radiobuttonlist, at.AreaTerapeuticaSelect(), "Descripcion", "IdAT");
 }
Ejemplo n.º 11
0
        /// <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;
            }
        }
Ejemplo n.º 12
0
        public static void SetInitialFocus(System.Web.UI.Control control)
        {
            string scriptKey = "InitialFocus";

            if (control.Page == null)
            {
                throw new ArgumentException(
                          "The Control must be added to a Page before you can set the IntialFocus to it.");
            }
            if (control.Page.Request.Browser.EcmaScriptVersion.Major >= 1)
            {
                if (control.Page.ClientScript.IsClientScriptBlockRegistered(scriptKey))
                {
                    throw(new InvalidOperationException("There is already a control set with the " +
                                                        "initial focus."));
                }

                // Create JavaScript
                StringBuilder s = new StringBuilder();
                s.Append("\n<SCRIPT LANGUAGE='JavaScript'>\n");
                s.Append("<!--\n");
                s.Append("function SetInitialFocus() {\n");
                s.Append("   if(document.getElementById) {\n");
                s.Append("	     document.getElementById('");

                // s.Append(control.UniqueID);

//				if(control.HasControls())
//					s.Append(control.Controls[0].UniqueID);
//				else
                s.Append(control.UniqueID);

                // Set Focus on the selected item of a RadioButtonList
                if (control is System.Web.UI.WebControls.RadioButtonList)
                {
                    System.Web.UI.WebControls.RadioButtonList rbl =
                        (System.Web.UI.WebControls.RadioButtonList)control;

                    string suffix = "_0";
                    int    t      = 0;
                    foreach (System.Web.UI.WebControls.ListItem li in rbl.Items)
                    {
                        if (li.Selected)
                        {
                            suffix = "_" + t.ToString();
                            break;
                        }
                        t++;
                    }
                    s.Append(suffix);
                }

                // Set Focus on the first item of a CheckBoxList
                if (control is System.Web.UI.WebControls.CheckBoxList)
                {
                    s.Append("_0");
                }

                s.Append("').focus();\n");
                s.Append("    }\n");
                s.Append("}\n");

                s.Append("window.onload = SetInitialFocus;\n");

                s.Append("// -->\n");
                s.Append("</SCRIPT>");

                // Register Client Script
                control.Page.ClientScript.RegisterStartupScript(typeof(ControlExtender), "InitialFocus", s.ToString());
            }
        }
Ejemplo n.º 13
0
 public static void SetSelectionByValue(System.Web.UI.WebControls.RadioButtonList radioButtonList, string value)
 {
     SetSelectionByValue(radioButtonList.Items, value);
 }
Ejemplo n.º 14
0
 /// <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
     }
 }
Ejemplo n.º 15
0
        /// <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
            }
        }
Ejemplo n.º 16
0
 /// <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
     }
 }
Ejemplo n.º 17
0
 public void cargarDivisiones_RadioButtonList(ref System.Web.UI.WebControls.RadioButtonList radiobuttonlist)
 {
     Controles.LlenarRadioButtonList(ref radiobuttonlist, di.DivisionesActivoSelect(), "Descripcion", "IdDivision");
 }