当我将具有可绑定(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
最佳答案
我认为这可能是 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") %>' />
这是输出:
关于asp.net - asp.net 中的用户控件 (ascx) 及其可绑定(bind)属性未显示在数据容器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7590980/