using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyWeb.Data;
using MyWeb.Common;
using MyWeb.Business;
using AjaxPro;
using System.Text;
<asp:DataList ID="DataList1" runat="server" RepeatLayout="Flow">
<ItemTemplate>
<div class="m_status">
<div class="ava">
<a href="#">
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("AvatarUS") %>'
CssClass="ava_medium"/></a>
</div>
<div class="sta_content">
<div class="sta_title">
<p class="sta_detail">
<asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Detail") %>'></asp:Literal>
</p>
<div class="function">
<a class="sta_like left" href="#">Thích</a>
<a class="sta_cmt left" href="#">Bình luận</a>
<a class="sta_share left" href="#">Chia sẻ</a>
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:DataList>
我想在代码后面添加一个类似DataList(Default.aspx.cs)
如何制作?
答案 0 :(得分:0)
在数据列表的行数据绑定事件中,您可以添加一些控件来保存您要添加的控件的位置,例如:
在ItemTemplate中添加一个控件来保存将要加载的控件。
<asp:Panel runat="server" ID="pnlPlaceHolder">
<!-- the control will be added here -->
</asp:Panel>
并且在代码后面,在数据列表的RowDataBound上执行以下操作
Panel pnlPlaceHolder = (Panel)e.Item.FindControl("pnlPlaceHolder");
if (pnlPlaceHolder!= null)
{
// The new control, a button, by example
Button btn = new Button();
btn.Text = "Added dinamically";
pnlPlaceHolder.Controls.Add(btn);
}
就是这样。
答案 1 :(得分:0)
我在后面添加代码时出现问题:Default.aspx.cs
namespace KetBanBonPhuong
{
[AjaxPro.AjaxNamespace("Default")]
public partial class Default1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Default1));
if(!isPostBack)
{
DataList dl = new DataList();
dl.DataSource = GetList();
dl.DataBind();
this.liststatus.Controls.Add(dl);
dl.DataSource = GetList();
dl.RepeatLayout = RepeatLayout.Flow;
Literal ltr = new Literal();
ltr.Text = "kaldfs";
dl.Controls.Add(ltr);//Error here
}
}
}