2010-02-04 49 views
3

我正在使用多個ObjectDataSources來填充FormView中的ComboBox字段。 FormView是通用的,因爲它的外觀根據它的類別而不同。在ObjectDataSource上使用選擇屬性而不是'SelectMethod'?

該類別在網頁的url中定義。我想創建一個類來過濾出類別並公開可用於填充ComboBox字段的多個屬性。

問題是,默認的ObjectDataSource只有一個屬性'SelectMethod'來檢索數據。有了這個類我想創建,它不會是方法,但會包含數據的屬性。

難道這是不知何故仍然可以將屬性分配給'SelectMethod'(或類似的)?使用另一種方法更好嗎?

謝謝。

回答

8

也許我我錯過了什麼。但是,如果您要將財產分配爲SelectMethod,則必須將其設置爲get_{Property Name}

+0

不知道這個把戲,會試試看,謝謝。 – 2010-02-11 07:58:04

+0

非常感謝你爲這個寶石。 – 2011-09-28 13:01:28

0

如果你想分配一個SelectMethod dynamicaly,你可以這樣做:

//你說該類別來自網址,因此,在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; 
       } 

      } 
     } 
    } 
相關問題