範例中在每個row裡都有一個LinkButton,去觸發RowCommand事件。
<asp:linkbutton id="lbtnPath" text="下載" CommandName="DownLoad" runat="server" ></asp:LinkButton>
然後就在RowCommand寫入下面的code:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.IndexOf("DownLoad")>=0)
{
//取得發生RowCommand事件的row
LinkButton tmLB = (LinkButton)e.CommandSource;
GridViewRow gvr = (GridViewRow)tmLB.NamingContainer;
...
}
}