另一种更复杂的方式是:
<asp:LinkButton class="uibutton normal submit" ID="LinkButtonMAR"
OnClick="LinkButtonMAR_Click" runat="server">Mark as Read
</asp:LinkButton>
<asp:HiddenField ID="NoteID" runat="server" Value='<%# Eval("NoteID")%>' />
代码背后:
protected void LinkButtonMAR_Click(object sender, EventArgs e)
{
LinkButton thisLinkBUtton = (LinkButton)sender;
// substitute appropriate object for the GridViewRow below
GridViewRow thisGridViewRow = (GridViewRow)thisLinkBUtton.Parent.Parent;
HiddenField hdnNoteID = (HiddenField)thisGridViewRow.FindControl("NoteID");
// run your update code...
}
我用过这个,但它让我不得不使用 Parent.Parent。另外,我需要来自同一行的其他数据。