0

我想在自定义服务器控件中为这样的属性添加一些选项

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

所以我可以使用选项列表设置自定义控件属性,例如

当您设置控件 AutoPostBack 属性时,您可以在下拉列表中找到两个选项来选择“真”或“假”..

我想在我的自定义服务器控件中做一些类似的事情..

4

1 回答 1

0

Try this

This is simple Demo..If you want to Option than try to use enum type property

aspx page

<%@ 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>

User Control

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

User Control Code behind

    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();
    }
于 2013-08-17T06:41:43.340 回答