.net 后台动态添加datalist 并绑定
[csharp]public void GetDataListData(string standardclass, string toothtypeBig, int i)
{
DataTable dt = bindData(standardclass, toothtypeBig);
DataList d = new DataList();
d.ID = "dlstTest";
d.ItemTemplate = new MyColumn("litData", 200);
d.RepeatColumns = 5;
d.RepeatDirection = RepeatDirection.Horizontal;
d.ItemDataBound += new DataListItemEventHandler(d_ItemDataBound);
d.DataSource = dt;
d.DataBind();
HtmlGenericControl div = new HtmlGenericControl("div");
div.Attributes.Add("class", "ProductIntroList");
if (i == 0)
div.Style.Add("display", "block");
else
div.Style.Add("display", "none");
div.Controls.Add(d);
this.divList.Controls.Add(div);
}
private void d_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
Literal t;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
t = (Literal)e.Item.FindControl("litData");
if (t != null)
{
string ulstring = string.Format(@"<ul><li><a class='ImageBlock' href='ProductInfor.aspx?{0}'>
<img width='126px' height='106px' src='imgProduct/{1}' border='0' /></a>
<a class='TextBlock' href='ProductInfor.aspx?{0}'> {2}-{3}</a></li>
</ul>", ((DataRowView)e.Item.DataItem).Row["Url"].ToString(), ((DataRowView)e.Item.DataItem).Row["ImageUrl"].ToString(), ((DataRowView)e.Item.DataItem).Row["Name"].ToString(), ((DataRowView)e.Item.DataItem).Row["CDescription"].ToString());
t.Text = ulstring;
}
}
}
public DataTable bindData(string _standardclass, string _toothtypebig)
{
this.divShopNull.Visible = false;
try
{
string sql = @"select DISTINCT Name,CDescription,StandardClass,Groove,HeadType,ToothTypeBig from ba_ShellTrumpet where 1=1 ";
if (_standardclass != "")
{
sql += "and StandardClass='" + _standardclass + "'";
}
if (_toothtypebig != "")
sql += " and ToothTypeBig='" + _toothtypebig + "'";
sql += "order by Name";
DataTable standard = BLL.GetDataTable(sql);
if (!CommonClass.DTRow.CheckDtIsEmpty(standard))
{
standard.Columns.Add("Url", typeof(string));
standard.Columns.Add("ImageUrl", typeof(string));
for (int i = 0; i < standard.Rows.Count; i++)
{
 
补充:Web开发 , ASP.Net ,