2013-08-17 54 views
0

添加的選項列表的屬性我想一些選項自定義服務器控件添加到一個屬性這樣如何在自定義服務器控件在asp.net

[ 
     Category("Appearance"), 
     DefaultValue(""), 
     Description("The text to display on the button.") 
    ] 
      public string SomeProperty 
      { 
       get 
       { 
        EnsureChildControls(); 
        return somevalue; 
       } 
       set 
       { 
        EnsureChildControls(); 
        value; 
       } 
      } 

,所以我可以設置自定義列表使用控件屬性對於例如

當您設置一個控制AutoPostBack屬性

選項,你可以在下拉列表中選擇兩個選項,選擇「真」或「假」 ..

我想去做的一些事情在我的自定義服務器控制..

+0

我正在使用自定義服務器控件而不是用戶控件'.ascx',請注意區別 –

回答

0

試試這個要選比

這是簡單Demo..If嘗試使用枚舉 type屬性

aspx頁面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Testing.WebForm2" %> 

<%@ Register Src="~/test.ascx" TagName="test" TagPrefix="uc" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <uc:test ID="ucArraerEmployee" runat="server" SelectedOption="Option3" /> 
    </div> 
    </form> 
</body> 
</html> 

用戶控制

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="test.ascx.cs" Inherits="Testing.test" %> 
Display: <asp:Label Text="text" runat="server" ID="lbl"/> 

用戶控制碼

public enum Options 
    { 
     Option1 = 1, 
     Option2 = 2, 
     Option3 = 3, 
    } 
    public virtual Options SelectedOption { get; set; } 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     lbl.Text = SelectedOption.ToString(); 
    } 
+0

iam使用自定義服務器控件而不是用戶控件,注意區別 –

相關問題