代码之家  ›  专栏  ›  技术社区  ›  Herman Cordes

在ObjectDataSource上使用Selection属性而不是“SelectMethod”?

  •  3
  • Herman Cordes  · 技术社区  · 16 年前

    我正在使用多个ObjectDatasource填充FormView中的组合框字段。formView有点普通,因为它的外观因其类别而异。

    类别在网页的URL中定义。我想创建一个类,它过滤掉类别并公开几个属性,这些属性可用于填充组合框字段。

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

    在某种程度上,是否仍然可以为“selectmethod”(或类似的方法)分配属性?使用其他方法更好吗?

    谢谢。

    2 回复  |  直到 11 年前
        1
  •  8
  •   m3kh    16 年前

    也许我错过了什么。但如果你想把财产转让给 SelectMethod ,您必须将其设置为 get_{Property Name} .

        2
  •  0
  •   Dale Wilson    11 年前

    如果要尝试分配SelectMethod dynamicaly,可以执行以下操作:

    //你说类别来自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;
                  }
    
                }
            }
        }
    
    推荐文章