zoukankan      html  css  js  c++  java
  • .Net数据源自定义参数

    1.web控件源码
    namespace ControlLibrary {
        
    using System;
        
    using System.Data;
        
    using System.Configuration;
        
    using System.Web;
        
    using System.Web.Security;
        
    using System.Web.UI;
        
    using System.Web.UI.WebControls;
        
    using System.Web.UI.WebControls.WebParts;
        
    using System.Web.UI.HtmlControls;


        
    public class PagePropertyParameter : Parameter {

            
    private String _key;

            
    public String Key {
                
    get {
                    
    return _key;
                }

                
    set {
                    _key 
    = value;
                }

            }


            
    protected override object Evaluate(HttpContext context, Control control) {
                Type t 
    = control.Page.GetType();
                System.Reflection.PropertyInfo pi 
    = t.GetProperty(Key, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic);
                
    return pi.GetValue(control.Page, null);
            }

        }


        
    public class ViewStateParameter : Parameter {

            
    private String _key;

            
    public String Key {
                
    get {
                    
    return _key;
                }

                
    set {
                    _key 
    = value;
                }

            }


            
    protected override object Evaluate(HttpContext context, Control control) {
                Type t 
    = control.Page.GetType();
                System.Reflection.PropertyInfo pi 
    = t.GetProperty("ViewState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                StateBag pageViewState 
    = pi.GetValue(control.Page, nullas StateBag;
                
    return pageViewState[Key];
            }

        }


        
    public class RequestParameter : Parameter
        
    {
            
    private String _key;

            
    public String Key
            
    {
                
    get
                
    {
                    
    return _key;
                }

                
    set
                
    {
                    _key 
    = value;
                }

            }


            
    protected override object Evaluate(HttpContext context, Control control)
            
    {
                
    return context.Request.Params.Get(_key);
               
    // return base.Evaluate(context, control);
            }

        }

    }
    2.使用方法
      <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString1 %>"
                ProviderName="<%$ ConnectionStrings:pubsConnectionString1.ProviderName %>" SelectCommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores] WHERE ([stor_name] LIKE '%' + @stor_name + '%')">
                <SelectParameters>
                    <%--<cc1:ViewStateParameter Name="stor_name" Key="TestState" Type="String" />--%>
                   <%-- <cc1:PagePropertyParameter Name="stor_name" Key="TestValue" Type="String" />--%>
                    <cc1:RequestParameter Name="stor_name" Key="Name" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
  • 相关阅读:
    移动端IM系统的协议选型:UDP还是TCP?
    【原创】新手入门一篇就够:从零开发移动端IM
    【原创】轻量级即时通讯技术MobileIMSDK:Android客户端开发指南
    【原创】轻量级移动设备即时通讯技术MobileIMSDK的常见问题解答
    【原创】轻量级移动端即时通讯技术 MobileIMSDK 发布了
    实时视频直播客户端技术盘点:Native、HTML5、WebRTC、微信小程序
    腾讯技术分享:腾讯是如何大幅降低带宽和网络流量的(图片压缩篇)
    微信团队分享:微信移动端的全文检索多音字问题解决方案
    IM开发基础知识补课(四):正确理解HTTP短连接中的Cookie、Session和Token
    腾讯技术分享:Android版手机QQ的缓存监控与优化实践
  • 原文地址:https://www.cnblogs.com/CSharp/p/939886.html
Copyright © 2011-2022 走看看