Пример #1
0
        private Dictionary <string, string> SetFieldValues(int _channel_id)
        {
            DataTable dt = new BLL.article_attribute_field().GetList(_channel_id, "").Tables[0];
            Dictionary <string, string> dic = new Dictionary <string, string>();

            foreach (DataRow dr in dt.Rows)
            {
                //查找相应的控件
                switch (dr["control_type"].ToString())
                {
                case "single-text":     //单行文本
                    TextBox txtControl = FindControl("field_control_" + dr["name"].ToString()) as TextBox;
                    if (txtControl != null)
                    {
                        dic.Add(dr["name"].ToString(), txtControl.Text.Trim());
                    }
                    break;

                case "multi-text":     //多行文本
                    goto case "single-text";

                case "editor":     //编辑器
                    HtmlTextArea htmlTextAreaControl = FindControl("field_control_" + dr["name"].ToString()) as HtmlTextArea;
                    if (htmlTextAreaControl != null)
                    {
                        dic.Add(dr["name"].ToString(), htmlTextAreaControl.Value);
                    }
                    break;

                case "images":     //图片上传
                    goto case "single-text";

                case "number":     //数字
                    goto case "single-text";

                case "checkbox":     //复选框
                    CheckBox cbControl = FindControl("field_control_" + dr["name"].ToString()) as CheckBox;
                    if (cbControl != null)
                    {
                        if (cbControl.Checked == true)
                        {
                            dic.Add(dr["name"].ToString(), "1");
                        }
                        else
                        {
                            dic.Add(dr["name"].ToString(), "0");
                        }
                    }
                    break;

                case "multi-radio":     //多项单选
                    RadioButtonList rblControl = FindControl("field_control_" + dr["name"].ToString()) as RadioButtonList;
                    if (rblControl != null)
                    {
                        dic.Add(dr["name"].ToString(), rblControl.SelectedValue);
                    }
                    break;

                case "multi-checkbox":     //多项多选
                    CheckBoxList cblControl = FindControl("field_control_" + dr["name"].ToString()) as CheckBoxList;
                    if (cblControl != null)
                    {
                        StringBuilder tempStr = new StringBuilder();
                        for (int i = 0; i < cblControl.Items.Count; i++)
                        {
                            if (cblControl.Items[i].Selected)
                            {
                                tempStr.Append(cblControl.Items[i].Value.Replace(',', ',') + ",");
                            }
                        }
                        dic.Add(dr["name"].ToString(), SFUtils.DelLastComma(tempStr.ToString()));
                    }
                    break;
                }
            }
            return(dic);
        }