在html里获取行索引
GridView可使用 <%# Container.DataItemIndex %>
DataList可使用 <%# Container.ItemIndex %>
DataList使用:
1. 前台<fsl:FSLLabel ID="lblAppCode" runat="server" Text='<%# Eval("AppCode") %>' ></fsl:FSLLabel>
<fsl:FSLButton ID="FSLButFavorite" runat="server" SkinID="fslDefaultButton" Text="收藏"
CommandName="insertFavorite" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "AppId") %>' />
后台:
protected void dstService_ItemCommand(object source, DataListCommandEventArgs e)
{
Label lblCode = (Label)e.Item.FindControl("lblAppCode");
string commandName =(string) e.CommandName;
}
protected void dstService_ItemDataBound(object source, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string appcode = ((DataRowView)e.Item.DataItem)["AppCode"].ToString();
System.Web.UI.WebControls.Button butCancle = ((System.Web.UI.WebControls.Button)e.Item.FindControl("FSLButCancleFavorite"));
}
}