请注意这张照片:
我希望能够点击“15”(或其他任何一个(它们都是链接按钮))BatchID值并触发一个事件,在该事件中我希望能够解析其值单击的[linkbutton]值。
因此,例如,如果你点击22,它会触发事件,我希望能够解析被点击的按钮的值(22)。
这是我的gridview代码:
<asp:GridView runat="server" ID="HSMGrid"
AutoGenerateColumns="false"
DataKeyNames="Status"
OnRowCommand="grdvwSearchDepositTransaction_RowCommand" OnRowDataBound="grdSearch_RowDataBound" ShowHeaderWhenEmpty="true"
CssClass="grid" Width="650">
<HeaderStyle CssClass="HeaderTemplate" />
<FooterStyle CssClass="FooterTemplate" />
<Columns>
<asp:TemplateField HeaderText="BatchID">
<ItemTemplate>
<asp:LinkButton runat="server" ID="btnBatchId" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "TransactionGroupsEntry.groupID") %>' OnClick="btnBatchId_Click" Text='<%# DataBinder.Eval(Container.DataItem, "TransactionGroupsEntry.groupID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TransactionGroupsEntry.bankNumber" HeaderText="Bank" ItemStyle-CssClass="mediumColumn columnCenter" />
<asp:BoundField DataField="TransactionGroupsEntry.branchNumber" HeaderText="Branch" ItemStyle-CssClass="mediumColumn columnCenter" />
<asp:BoundField DataField="TransactionGroupsEntry.cashInTicketAmount" HeaderText="Cash-In Ticket Amount" ItemStyle-CssClass="mediumColumn columnCenter" />
<asp:BoundField DataField="TransactionGroupsEntry.createdBy" HeaderText="Created By" ItemStyle-CssClass="mediumColumn columnCenter" />
<asp:BoundField DataField="TransactionGroupsEntry.dateCreated" HeaderText="Date Created" ItemStyle-CssClass="mediumColumn columnCenter" />
</Columns>
<EmptyDataTemplate>
<span style="font-weight: bold;">No Transactions have been entered</span>
</EmptyDataTemplate>
</asp:GridView>
这是它发生的事件:
protected void btnBatchId_Click(object sender, EventArgs e)
{
}
答案 0 :(得分:2)
您只需将sender
转换为LinkButton
并使用它的Text
属性:
protected void btnBatchId_Click(object sender, EventArgs e)
{
LinkButton link = (LinkButton) sender;
string batchID = link.Text;
}