码迷,mamicode.com
首页 > Web开发 > 详细

DevExpress学习之ASPxGridView后台增加列

时间:2015-06-25 12:11:05      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

 

public void BindRecordList()

{

    String sqlAll=”select ID,”;

     if (ASPxGridView1.Columns.Count == 0)

            {

                //手动绑定数据

                DevExpress.Web.ASPxGridView.GridViewDataTextColumn dl = newDevExpress.Web.ASPxGridView.GridViewDataTextColumn();

dl.Caption = "显示出来的头部";

                dl.FieldName = "AgentId";

                gvRecordList.Columns.Add(dl);

                //从数据库中取的要绑定的列名与描述

                DataTable dsWidth = gd.getGradeReg();

                String Sqlcolumn=””;

                for (int i = 0; i < dsWidth.Rows.Count; i++)

                {

                    DevExpress.Web.ASPxGridView.GridViewDataTextColumn datacolumn = newDevExpress.Web.ASPxGridView.GridViewDataTextColumn();

                    //绑定列的描述

                    datacolumn.Caption = dsWidth.Rows[i]["GrShow"].ToString();

                    //绑定列的字段

                    datacolumn.FieldName = dsWidth.Rows[i]["GrName"].ToString().Trim();

                    datacolumn.UnboundType = DevExpress.Data.UnboundColumnType.Bound;

                    ASPxGridView1.Columns.Add(datacolumn);

                    //取得sql语句中的字段

                    Sqlcolumn+=” , “+ dsWidth.Rows[i]["GrName"].ToString().Trim()

                }

            }

            DataSet dsRecord = null;

            try

            {//取得完整的sql语句

                sqlAll += ColonmFileds + " from Recording " + sqlQuery();

                dsRecord = SQLHelper.Query(sqlAll);

                //绑定数据源

                ASPxGridView1.DataSource = dsRecord.Tables[0].DefaultView;

                ASPxGridView1.DataBind();

            }

            catch

            {

                throw;

            }

        }

GridView在后台动态绑定列或者增加列的语句为:

for (int i = 0; i < dsWidth.Rows.Count; i++)

            {

                BoundField bf = new BoundField();

                bf.DataField = dsWidth.Rows[i]["GrName"].ToString().Trim();//字段名

                bf.HeaderText = dsWidth.Rows[i]["GrShow"].ToString();//列名

                GridView1.Columns.Insert(i, bf);

            }

DevExpress学习之ASPxGridView后台增加列

标签:

原文地址:http://www.cnblogs.com/Mh201454/p/4599470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!