示例#1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Id", typeof(int));
            dt.Columns.Add("Name", typeof(string));

            string sSearch = tbSearchString.Text.Trim();

            MetaObject[] list;
            if (sSearch == String.Empty)
            {
                list = MetaObject.List(mc);
            }
            else
            {
                FilterElement filter = new FilterElement(mc.TitleFieldName, FilterElementType.Like, "%" + sSearch + "%");
                list = MetaObject.List(mc, filter);
            }

            foreach (MetaObject obj in list)
            {
                DataRow row = dt.NewRow();
                row["Id"]   = obj.PrimaryKeyId;
                row["Name"] = obj.Properties[mc.TitleFieldName].Value.ToString();
                dt.Rows.Add(row);
            }

            if (ViewState["SelectItem_Sort"] == null)
            {
                ViewState["SelectItem_Sort"] = "Name";
            }
            if (ViewState["SelectItem_CurrentPage"] == null)
            {
                ViewState["SelectItem_CurrentPage"] = 0;
            }
            if (dt.Rows != null && dt.Rows.Count < grdMain.PageSize)
            {
                grdMain.AllowPaging = false;
            }
            else
            {
                grdMain.AllowPaging = true;
            }
            DataView dv = dt.DefaultView;

            dv.Sort = ViewState["SelectItem_Sort"].ToString();
            if (ViewState["SelectItem_CurrentPage"] != null && grdMain.AllowPaging)
            {
                grdMain.CurrentPageIndex = (int)ViewState["SelectItem_CurrentPage"];
            }
            grdMain.DataSource = dv;
            grdMain.DataBind();

            foreach (DataGridItem dgi in grdMain.Items)
            {
                ImageButton ib = (ImageButton)dgi.FindControl("ibRelate");
                if (ib != null)
                {
                    string sId     = dgi.Cells[0].Text;
                    string sAction = CHelper.GetCloseRefreshString(RefreshButton.Replace("xxx", sId));
                    ib.Attributes.Add("onclick", sAction);
                }
            }
        }
        private void BindGrid()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Id", typeof(PrimaryKeyId));
            dt.Columns.Add("Name", typeof(string));

            string sSearch = tbSearchString.Text.Trim();

            MetaClass mc = MetaDataWrapper.GetMetaClassByName(ddClasses.SelectedValue);

            if (mc == null)
            {
                return;
            }

            MetaObject[] list = MetaObject.List(mc);

            foreach (MetaObject obj in list)
            {
                DataRow row = dt.NewRow();
                row["Id"]   = obj.PrimaryKeyId.Value;
                row["Name"] = CHelper.GetResFileString(obj.Properties[mc.TitleFieldName].Value.ToString());
                dt.Rows.Add(row);
            }

            if (ViewState["SelectItem_Sort"] == null)
            {
                ViewState["SelectItem_Sort"] = "Name";
            }
            if (ViewState["SelectItem_CurrentPage"] == null)
            {
                ViewState["SelectItem_CurrentPage"] = 0;
            }
            if (dt.Rows != null && dt.Rows.Count < grdMain.PageSize)
            {
                grdMain.AllowPaging = false;
            }
            else
            {
                grdMain.AllowPaging = true;
            }
            DataView dv = dt.DefaultView;

            if (sSearch != String.Empty)
            {
                dv.RowFilter = String.Format(CultureInfo.InvariantCulture, "Name LIKE '%{0}%'", sSearch);
            }
            dv.Sort = ViewState["SelectItem_Sort"].ToString();
            if (ViewState["SelectItem_CurrentPage"] != null && grdMain.AllowPaging)
            {
                grdMain.CurrentPageIndex = (int)ViewState["SelectItem_CurrentPage"];
            }
            grdMain.DataSource = dv;
            grdMain.DataBind();

            foreach (DataGridItem dgi in grdMain.Items)
            {
                ImageButton ib = (ImageButton)dgi.FindControl("ibRelate");
                if (ib != null)
                {
                    string sId     = ddClasses.SelectedValue + "_" + dgi.Cells[0].Text;
                    string sAction = CHelper.GetCloseRefreshString(RefreshButton.Replace("xxx", sId));
                    ib.Attributes.Add("onclick", sAction);
                }
            }
        }
示例#3
0
        private void BindGrid()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Id", typeof(string));
            dt.Columns.Add("Name", typeof(string));

            string sSearch = tbSearchString.Text.Trim();

            FilterElementCollection fec = new FilterElementCollection();

            if (!String.IsNullOrEmpty(Request["filterName"]) && !String.IsNullOrEmpty(Request["filterValue"]))
            {
                FilterElement fe   = FilterElement.EqualElement(Request["filterName"], Request["filterValue"]);
                FilterElement fe1  = FilterElement.IsNullElement(Request["filterName"]);
                FilterElement feOr = new OrBlockFilterElement();
                feOr.ChildElements.Add(fe);
                feOr.ChildElements.Add(fe1);
                fec.Add(feOr);
            }
            else if (!String.IsNullOrEmpty(Request["filterName"]) && String.IsNullOrEmpty(Request["filterValue"]))
            {
                FilterElement fe = FilterElement.IsNullElement(Request["filterName"]);
                fec.Add(fe);
            }

            MetaObject[] list = MetaObject.List(mc, fec.ToArray());

            foreach (MetaObject obj in list)
            {
                DataRow row = dt.NewRow();
                row["Id"] = obj.PrimaryKeyId.ToString();
                if (obj.Properties[mc.TitleFieldName].Value != null)
                {
                    row["Name"] = CHelper.GetResFileString(obj.Properties[mc.TitleFieldName].Value.ToString());
                }
                dt.Rows.Add(row);
            }

            if (ViewState["SelectItem_Sort"] == null)
            {
                ViewState["SelectItem_Sort"] = "Name";
            }
            if (ViewState["SelectItem_CurrentPage"] == null)
            {
                ViewState["SelectItem_CurrentPage"] = 0;
            }
            if (dt.Rows != null && dt.Rows.Count < grdMain.PageSize)
            {
                grdMain.AllowPaging = false;
            }
            else
            {
                grdMain.AllowPaging = true;
            }
            DataView dv = dt.DefaultView;

            if (sSearch != String.Empty)
            {
                dv.RowFilter = String.Format(CultureInfo.InvariantCulture, "Name LIKE '%{0}%'", sSearch);
            }
            dv.Sort = ViewState["SelectItem_Sort"].ToString();
            if (ViewState["SelectItem_CurrentPage"] != null && grdMain.AllowPaging)
            {
                grdMain.CurrentPageIndex = (int)ViewState["SelectItem_CurrentPage"];
            }
            grdMain.DataSource = dv;
            grdMain.DataBind();

            foreach (DataGridItem dgi in grdMain.Items)
            {
                ImageButton ib = (ImageButton)dgi.FindControl("ibRelate");
                if (ib != null)
                {
                    string sId     = dgi.Cells[0].Text;
                    string sAction = CHelper.GetCloseRefreshString(RefreshButton.Replace("xxx", sId));
                    ib.Attributes.Add("onclick", sAction);
                }
            }
        }