[英]Repeater using a user control
I have a repeater with which I want to use to show a user control multiple times, populated with data. 我有一个中继器,可以用来多次显示用户控件,并填充数据。
Currently, I have this: 目前,我有这个:
<asp:Repeater runat="server" ID="MyRepeater" >
<ItemTemplate>
<uc1:MyItems ID="MyItems1" runat="server" />
</ItemTemplate>
</asp:Repeater>
My user control has three properties, which I want to populate for each. 我的用户控件具有三个属性,我想为每个属性填充。 I currently have this:
我目前有这个:
protected void Page_Load(object sender, EventArgs e)
{
MyDataSource.SelectCommand =
"SELECT Name, Address, Phone " +
"FROM TestTable ";
MyDataSource.SelectCommandType = SqlDataSourceCommandType.Text;
DataView resultsdv = (DataView)MyDataSource.Select(DataSourceSelectArguments.Empty);
foreach (DataRow dr in resultsdv.Table.Rows)
{
MyItems1.Cust_Name = dr["Name"].ToString();
MyItems1.Cust_Address = dr["Address"].ToString();
MyItems1.Cust_Tel = dr["Phone"].ToString();
}
}
Obviously, this isn't doing what I want. 显然,这不是我想要的。 Is it possible to tell the repeater that I want to populate my user control – either by data binding it, or manually populate it in a way similar to above?
是否可以通过数据绑定或以类似于上述的方式手动填充来告诉转发器我要填充用户控件?
<asp:Repeater runat="server" ID="MyRepeater" >
<ItemTemplate>
<uc1:MyItems ID="MyItems1" MyItems="<%# Eval("Name") %>" ... runat="server" />
</ItemTemplate>
</asp:Repeater>
protected void Page_Load(object sender, EventArgs e)
{
MyDataSource.SelectCommand =
"SELECT Name, Address, Phone " +
"FROM TestTable ";
MyDataSource.SelectCommandType = SqlDataSourceCommandType.Text;
DataView resultsdv = (DataView)MyDataSource.Select(DataSourceSelectArguments.Empty);
MyRepeater.DataSource = resultsdv.Table.Rows;
MyRepeater.DataBind()
}
I think that needs some corrections: 我认为需要进行一些更正:
<asp:Repeater runat="server" ID="MyRepeater" >
<ItemTemplate>
<uc1:MyItems ID="MyItems1" Cust_Name=<%#Eval("Name") %> Cust_Address=<%#Eval("Address")%> Cust_Tel=<%#Eval("Phone")%> runat="server" />
</ItemTemplate>
</asp:Repeater>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.