在RowCommand事件中獲取索引值
1.利用e.CommandSource
代碼如下:
protected void lpg_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ItemCollect")
{
GridViewRow gvr = (GridViewRow)(((LinkButton)(e.CommandSource)).NamingContainer);
LinkButton lk = lpgKnowledgeExchange.Rows[gvr.RowIndex].FindControl("lbtnCollect") as LinkButton;
}
}
2.如果是模板列中的button直接click事件利用sender 取其parent 也可以實現(xiàn)
更多信息請查看IT技術(shù)專欄