asp.net - asp.net 中的用户控件 (ascx) 及其可绑定(bind)属性未显示在数据容器中

标签 asp.net data-binding listview user-controls properties

当我将具有可绑定(bind)属性的用户控件添加到 asp.net 页面时,当我单击 Repeater-Listview 上的编辑数据绑定(bind)时,我在设计器的对话框中看不到它的可绑定(bind)属性

我应该添加任何其他属性描述符吗?

在转发器或类似控件中的标记会像这样

<uc1:Menu ID="Menu1" superman="<% Eval("userid") %>" runat="server" />

关于我只使用的可绑定(bind)属性

[System.ComponentModel.DefaultBindingProperty("superman")]
    [System.ComponentModel.Bindable(true)]
    public int superman
    {
        get;
        set;
    }

People discuss it here but they couldn't find a solution

This is the problematic place


And this is the definition of the user control

最佳答案

我认为这可能是 Visual Studio 的问题,我还没有找到显示用户控件属性的方法,但是,即使属性没有出现在选项框中,您仍然可以绑定(bind)该属性:

这是你绑定(bind)它的方式:

在后面的用户控件代码中:

[Bindable(true)]
public string MyProperty
{
    get
    {
        return this.lblMessage.Text;
    }
    set
    {
        this.lblMessage.Text = value + DateTime.Now.ToString();
    }
}

在 ASCX 文件中:

<asp:Label ID="lblMessage" Text="something" runat="server" />

在 ASPX 页面中:

<asp:DataList runat="server" ID="dataList" Width="50%" 
    DataSourceID="ObjectDataSource1">
    <ItemTemplate>
        <uc1:WebUserControl1 runat="server" ID="myUC" MyProperty='<%# Eval("Name") %>' />
    </ItemTemplate>
</asp:DataList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
    SelectMethod="GetProducts" TypeName="WebApplication1.Repository">
</asp:ObjectDataSource>

简单的只需在标签中添加您在 UC 中创建的属性:

<uc1:WebUserControl1 runat="server" ID="myUC" MyProperty='<%# Eval("Name") %>' />

这是输出:

enter image description here

关于asp.net - asp.net 中的用户控件 (ascx) 及其可绑定(bind)属性未显示在数据容器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7590980/

相关文章:

javascript - Cors 问题仅在 "put"时发生?

c# - 使用列表框进行数据绑定(bind)

android - 如何在 Espresso 中选择 ListView ?

asp.net - MS 图表控件的替代品?

ASP.NET MVC : Application_Start and Url. 操作

.net - 使用 WriteValue 手动绑定(bind)数据

具有显式转换的 WPF 绑定(bind)

从另一个 Activity 返回时,android setOnItemClickListener 不响应

c# - 如何在没有setter的情况下实现INotifyPropertyChanged?

.net - 在 .NET 中调用 HttpHandler 文件的最简单方法是什么?