0
我想創建一種方法,接受多種類型的控件 - 在這種情況下,標籤和麪板。轉換不起作用,因爲IConvertible不轉換這些類型。任何幫助將如此讚賞。 在此先感謝創建方法來處理多種類型的控件
public void LocationsLink<C>(C control)
{
if (control != null)
{
WebControl ctl = (WebControl)Convert.ChangeType(control, typeof(WebControl));
Literal txt = new Literal();
HyperLink lnk = new HyperLink();
txt.Text = "If you prefer a map to the nearest facility please ";
lnk.Text = "click here";
lnk.NavigateUrl = "/content/Locations.aspx";
ctl.Controls.Add(txt);
ctl.Controls.Add(lnk);
}
}
謝謝你的回答。您能否進一步採取措施,並說明我在該方法中還會做些什麼以促進轉換?同時,我將研究約束條件。 – Praesagus 2010-03-30 23:56:27
我擴展了我的帖子給你。 – Thomas 2010-03-31 00:37:23
謝謝你花時間解釋它。你剛剛給了我另一個偉大的工具。 – Praesagus 2010-03-31 14:59:55