惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
D
Docker
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
月光博客
月光博客
S
SegmentFault 最新的问题
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI

博客园 - sun@live

两段代码 <收藏>提高Web性能的14条法则(详细版) MOSS与业务系统的集成 之 单点登录 MOSS与业务系统的集成 之 自定义Membership实现Forms方式验证 手机归属地数据—采集 JavaScript和CSS速查手册 序列化一个字符串到CDATA元素(.NET 1.1) Sandcastle工具SandcastleBuilder 清除字符串数组中,重复元素 - sun@live - 博客园 Windows Live Writer 写的一个双向选择器(JS) 论坛中,用户权限解决方法 (原创)一个改自java的代码统计工具 Web2.0用户注册,激活,密码找回模块 [学习日志]EyasBlog控件部分已基本完成-2005-12-03 学习日志(blog日历控件)-2005年11月12日 学习日志(Blog架构)-2005年11月09日 学习日志-2005年11月09日 学习计划-2005年11月07日
.Net数据源自定义参数
sun@live · 2007-10-27 · via 博客园 - sun@live

2007-10-27 19:43  sun@live  阅读(271)  评论()    收藏  举报

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>