2013-08-28 29 views
0

我需要在ASP.NET應用程序(使用VB)中創建一個動態構建的頁面。該頁面收集報告的參數信息。根據數據庫中的值創建控件

報告信息(如名稱,存儲過程和所需參數)位於數據庫表中。

在表中我有一個'control_type'字段,我希望我可以使用它作爲我需要創建的控件類型來收集所選報表的相關參數值。 所以,如果我選擇Report01,我得到了Report01的行數據庫,並且該報告行的參數數據告訴我需要將一個整數值收集到一個名爲i_company_id的參數中,並創建控件以選擇此值表單在我的動態創建的參數頁)說'DropDownList'。

如果我得到來自提交值到一個變量的DB和地點列,然後我像做

dim ddl as New VaraibleName 

,然後我可以填充列表爲正常,然後

panel.controls.add(ddl) 

關鍵是能夠創建一個控件,其中要創建的控件類型是以變量或其他動態定義的方式創建的。

+0

我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –

回答

0

我明白,以下解決方案可以提供你想要的東西:做

Private Function createVariable(inputName As String) As Object 
    Dim outVariable As Object = New Object 

    If (inputName = "DropDownList") Then 
     Dim targetVariable As DropDownList = New DropDownList() 
     With targetVariable 
      'You might change here its properties (passed via Object array for example) 
     End With 

     outVariable = targetVariable 
    End If 
    'Add as many conditions as variables you are expecting 

    Return outVariable 
End Function 

叫它:

Dim ddl As Object = createVariable("VariableName") 
panel.Controls.Add(ddl) 

如果您打算使用此代碼只是Controls,可以更換ObjectControl(將以任何方式工作)。

+0

可愛的主意!非常感謝。 – MarkO

+0

@MarkO不客氣。 – varocarbas

相關問題