Bind a Grid to an Expression

Overview

You can bind a grid to any expression. In this example, we bind a grid the results of a Web Service Listener Activity.

We start by binding the grid to the results of an expression that points to the Web service listener (or whichever activity you want).

You need to write a class, and use it as the form base class.

Code Behind

using System;
using PNMsoft.Sequence.Forms.Web.UI;
using PNMsoft.Sequence.Web.Compilation;
using Rad = PNMsoft.Rad.Web.UI;
using Sq = PNMsoft.Sequence.Forms.Web.UI.Controls;
 
namespace SequenceEx.Forms.Samples
{
    public class ExpressionDataSourceBasedGrid : FormControl
    {
        public ExpressionDataSourceBasedGrid()
        {
        }
 
        private bool IsInitialized
        {
            get
            {
                object o = this.ViewState["IsInitialized"];
                return o != null && (bool)o;
            }
            set
            {
                this.ViewState["IsInitialized"] = value;
            }
        }
 
        protected override void OnPreRender(EventArgs e)
        {
            if (!this.IsInitialized)
            {
                Sq.TextBox expressionTextBox = (Sq.TextBox)this.FindControl("ExpressionTextBox");
                Rad.RadGrid resultsGridView = (Rad.RadGrid)this.FindControl("ResultGridView");
 
                object ds = new SqExpressionBuilder().EvaluateExpression(expressionTextBox.Text, this, null, null);
 
                resultsGridView.DataSource = ds;
                resultsGridView.DataBind();
 
                this.IsInitialized = true;
            }
 
            base.OnPreRender(e);
        }
    }
}

Markup

<%@ Control Inherits="SequenceEx.Forms.Samples.ExpressionDataSourceBasedGrid, YOUR ASSEMBLY NAME " %>
  <sq:TextBox runat="server" ID="ExpressionTextBox" Visible="False" Text="{Form1}.Scope()"></sq:TextBox>
<sqr:RadGrid runat="server" ID="ResultGridView" AllowPaging="False">
</sqr:RadGrid>
<sq:BoundControl runat="server" TargetControlID="ResultGridView"></sq:BoundControl>