Custom Parameter for DataSource Control

by lichen 1/30/2006 8:01:00 PM

This post by Fredrik Normén is a big help. I need to create a custom parameter that binds to Context. I was able to create in minutes following the example. The result is:

    public class ContextParameter : System.Web.UI.WebControls.Parameter
    {
        private string _contextField;

        public ContextParameter()
        {
        }

        protected ContextParameter(ContextParameter original)
            : base(original)
        {
            this.ContextField = original.ContextField;
        }

        protected override object Evaluate(HttpContext context, Control control)
        {
            if (context != null && _contextField != null)
            {
                return context.Items[_contextField];
            }
            else
            {
                return null;
            }
        }

        protected override Parameter Clone()
        {
            return new ContextParameter(this);
        }


        public string ContextField
        {
            get
            {
                return _contextField;
            }
            set
            {
                _contextField = value;
            }
        }
    }
I can the use the parameter like:

<dt:ContextParameter Name="PageID" ContextField="PageID" Type="String" DefaultValue="136b08ff-3752-4704-8db8-cf323a98bfaa" />

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net | ASP.NET

相关文章

Comments are closed

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Pages

    Recent comments

    Authors

    Tags

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2012

      Sign in