我希望能够将一些动态信息从
.aspx页面:
listview
传递到UserControl
,但我猜我遗漏了什么。.aspx页面:
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource"
DataKeyNames="id_Image">
<ItemTemplate>
<uc1:Info Name_Lbl='<%# Bind("Name") %>' Description_Lbl='<%# Bind("Description")%>' ID="info1" runat="server" />
</ItemTemplate>
</asp:ListView>
.ascx文件:
Name:
<asp:Label ID="NameLabel" runat="server" />
Description:
<asp:Label ID="DescriptionLabel" runat="server" />
.ascx后台代码文件:
public string Name_Lbl { get; set; }
public string Description_Lbl { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
NameLabel.Text = Name_Lbl;
DescriptionLabel.Text = Description_Lbl;
}
如果我想从字符串文本中获取值,一切都正常:
<uc1:Info Name_Lbl="Name" Description_Lbl="Description" ID="info1" runat="server" />
但是当我尝试从Datasource
获取值时,用户控件中的字符串值为"null"。有人能看出我做错了什么吗?谢谢,Jim Oak。