【问题标题】:Use selection property instead of 'SelectMethod' on ObjectDataSource?在 ObjectDataSource 上使用选择属性而不是“SelectMethod”?
【发布时间】:2010-02-04 10:20:08
【问题描述】:

我正在使用多个 ObjectDataSource 来填充 FormView 中的 ComboBox 字段。 FormView 有点通用,因为它的外观因类别而异。

类别在网页的 url 中定义。我想创建一个类来过滤类别并公开几个属性,这些属性可用于填充 ComboBox 字段。

问题是,默认的 ObjectDataSource 只有一个属性“SelectMethod”来检索数据。我想创建这个类,它不是方法,而是包含数据的属性。

是否以某种方式仍然可以将属性分配给“SelectMethod”(或类似的)?使用其他方法更好吗?

谢谢。

【问题讨论】:

    标签: c# asp.net objectdatasource


    【解决方案1】:

    也许我错过了什么。但是如果你想将一个属性指定为SelectMethod,你必须将它设置为get_{Property Name}

    【讨论】:

    • 非常感谢您提供这颗宝石。
    【解决方案2】:

    如果您尝试动态分配 SelectMethod,您可以这样做:

    //你说类别来自Url,所以,在Page_Load方法中

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                // Get your QueryString variable
                if (Request["YourVariable"] != null)
                {
                 string yourVariable = Request["YourVariable"].ToString();
    
                  if (yourVariable == "CategoryX") {
    
                       ObjectDataSource1.SelectMethod = "SelectMethodFromCategoryX";
    
                       // and if you need to set SelectParameters to your ObjectDataSource
                       ObjectDataSource1.SelectParameters["pYourParameterNameForCategoryX"].DefaultValue = this.txtTest.Text;
                  }
    
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多