Exemple #1
0
        public virtual void AddColumn(DataGrid _grid)
        {
            MyWebControlLib.Columns columns = new MyWebControlLib.Columns();
            MyWebControlLib.Column  column  = null;
            //根据_configfile文件载入列信息
            XmlDocument doc = new XmlDocument();

            doc.Load(_configfile);
            XmlElement root = doc.DocumentElement;

            if (root.HasChildNodes)
            {
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    if (root.ChildNodes[i].LocalName.ToLower() == "columns")
                    {
                        XmlNode columnsnode = root.ChildNodes[i];
                        for (int j = 0; j < columnsnode.ChildNodes.Count; j++)
                        {
                            column = new MyWebControlLib.Column();
                            if (columnsnode.ChildNodes[j].Attributes["name"] != null)
                            {
                                column.FieldName = columnsnode.ChildNodes[j].Attributes["name"].Value.ToString();
                            }
                            if (columnsnode.ChildNodes[j].Attributes["namecn"] != null)
                            {
                                column.Title = columnsnode.ChildNodes[j].Attributes["namecn"].Value.ToString();
                            }
                            if (columnsnode.ChildNodes[j].Attributes["showingrid"] != null)
                            {
                                if (columnsnode.ChildNodes[j].Attributes["showingrid"].Value.ToString().ToLower() == "true")
                                {
                                    column.ShowInGrid = true;
                                }
                                else
                                {
                                    column.ShowInGrid = false;
                                }
                            }

                            if (columnsnode.ChildNodes[j].Attributes["width"] != null)
                            {
                                column.Width = Convert.ToInt32(columnsnode.ChildNodes[j].Attributes["width"].Value.ToString());
                            }
                            columns.Add(column);
                        }
                    }
                }
            }
            if (columns.Count > 0)
            {
                //将列增加至表格中
                BoundColumn field = null;
                //BoundField field = null;
                for (int i = 0; i < columns.Count; i++)
                {
                    field                   = new BoundColumn();//gridview 的boundfield对应datagrid的boundcolumn
                    field.HeaderText        = columns[i].Title;
                    field.DataField         = columns[i].FieldName;
                    field.HeaderStyle.Width = columns[i].Width;
                    if (columns[i].ShowInGrid == false)
                    {
                        field.Visible = false;
                    }
                    field.HeaderStyle.Wrap          = false;
                    field.ItemStyle.Wrap            = false;
                    field.ItemStyle.HorizontalAlign = HorizontalAlign.Left;
                    _grid.Columns.Add(field);
                }
            }
        }
Exemple #2
0
        public virtual void AddColumn(DataGrid _grid)
        {
            MyWebControlLib.Columns columns = new MyWebControlLib.Columns();
            MyWebControlLib.Column column = null;
            //����_configfile�ļ���������Ϣ
            XmlDocument doc = new XmlDocument();
            doc.Load(_configfile);
            XmlElement root = doc.DocumentElement;
            if (root.HasChildNodes)
            {
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    if (root.ChildNodes[i].LocalName.ToLower() == "columns")
                    {
                        XmlNode columnsnode = root.ChildNodes[i];
                        for (int j = 0; j < columnsnode.ChildNodes.Count; j++)
                        {
                            column = new MyWebControlLib.Column();
                            if (columnsnode.ChildNodes[j].Attributes["name"] != null)
                                column.FieldName = columnsnode.ChildNodes[j].Attributes["name"].Value.ToString();
                            if (columnsnode.ChildNodes[j].Attributes["namecn"] != null)
                                column.Title = columnsnode.ChildNodes[j].Attributes["namecn"].Value.ToString();
                            if (columnsnode.ChildNodes[j].Attributes["showingrid"] != null)
                            {
                                if (columnsnode.ChildNodes[j].Attributes["showingrid"].Value.ToString().ToLower() == "true")
                                    column.ShowInGrid = true;
                                else
                                    column.ShowInGrid = false;
                            }

                            if (columnsnode.ChildNodes[j].Attributes["width"] != null)
                            {
                                column.Width = Convert.ToInt32(columnsnode.ChildNodes[j].Attributes["width"].Value.ToString());
                            }
                            columns.Add(column);
                        }
                    }
                }
            }
            if (columns.Count > 0)
            {
                //���������������
                BoundColumn field = null;
                //BoundField field = null;
                for (int i = 0; i < columns.Count; i++)
                {
                    field = new BoundColumn();//gridview ��boundfield��Ӧdatagrid��boundcolumn
                    field.HeaderText = columns[i].Title;
                    field.DataField = columns[i].FieldName;
                    field.HeaderStyle.Width = columns[i].Width;
                    if (columns[i].ShowInGrid == false)
                    {
                        field.Visible = false;
                    }
                    field.HeaderStyle.Wrap = false;
                    field.ItemStyle.Wrap = false;
                    field.ItemStyle.HorizontalAlign = HorizontalAlign.Left;
                    _grid.Columns.Add(field);
                }
            }
        }