DataList获得ID问题
CS:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindTopMenu();
}
}
public void BindTopMenu()
{
this.DataList1.DataSource = Commodity.GetTopCommodityProducts(1, 4);
this.DataList1.DataBind();
}
数据方面:
CommodityId
8
7
5
3
HTML:
<img src="<%# DataBinder.Eval(Container.DataItem,"CommoditySmallPic","{0}") %>" alt="<%# DataBinder.Eval(Container.DataItem, "CommodityName", "{0}")%> "/>
<br /><%# Strings.CutString(Eval("CommodityName").ToString(),25)%>
<br /><%# DataBinder.Eval(Container.DataItem,"CommodityId","{0}")%>
<br /><%#Eval("CommodityId") %>
<br /><%# DataBinder.Eval(Container.DataItem,"CommodityId") %>
<br /><%#(int)DataBinder.Eval(Container.DataItem, "CommodityId")%>
CommoditySmallPic和CommodityName都读出来 并且显示了,可是CommodityId显示出来的结果是0
------解决方案--------------------
很长时间没做过ASP了。不过分析HTML的代码
<img src=" <%# DataBinder.Eval(Container.DataItem,"CommoditySmallPic","{0}") %>" alt=" <%# DataBinder.Eval(Container.DataItem, "CommodityName", "{0}")%> "/>
CommodityId的值应该没有读进来