我有一个带有按钮的GridView。我希望每行上的按钮获取GridView中每行第一个单元格的值。例如下表:
| Header 1 | Header 2 | Header 3 |
| Happy | Sad | Button 1 |
| Worry | Angry | Button 2 |
| Excited | Frown | Button 3 |
| Header 1 | Header 2 | Header 3 |
| Happy | Sad | Button 1 |
| Worry | Angry | Button 2 |
| Excited | Frown | Button 3 |
当我按下按钮1时,它将显示“Happy”。如果我按下按钮2,它将显示“Worry”。以此类推。请问如何实现这一功能。
.HTML
<asp:gridview id="grdCreateGroup" runat="server" DataKeyNames="id" AutoGenerateColumns="false" OnRowCommand="grdCreateGroup_RowCommand" OnRowDataBound="grdCreateGroup_RowDataBound">
<Columns>
<asp:BoundField DataField="admissionNo" HeaderText="Admission No." />
<asp:BoundField DataField="fullName" HeaderText="Full Name" />
<asp:templatefield headertext="">
<itemtemplate>
<asp:Button ID="btnSendInvite" runat="server" Text="Send Invite" CommandName="sendInvite" />
</itemtemplate>
</asp:templatefield>
</Columns>
</asp:gridview>
.CS
protected void grdCreateGroup_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "sendInvite")
{
account accounta = new account();
account accountb = new account();
accountManager accountManager = new accountManager();
invite invite = new invite();
inviteManager inviteManager = new inviteManager();
string emailAddress, admissionNo;
bool status = true;
emailAddress = HttpContext.Current.User.Identity.Name;
accounta = accountManager.getAccInfoByEmailAddress(emailAddress);
invite.leaderName = accounta.fullName;
invite.groupNo = accounta.groupNo;
//invite.recipientEmailAddress = accountb.recipientEmailAddress;
//status = inviteManager.sendInvite(invite);
GridViewRow Row = grdCreateGroup.Rows[0];
Button btnSendInvite = (Button)Row.FindControl("btnSendInvite");
if (status == true)
{
divMessage.InnerHtml = invite.groupNo.ToString();
btnSendInvite.Text = "Invite Sent";
btnSendInvite.Enabled = false;
}
else
{
divMessage.InnerHtml = "Record not added in database";
}
}
}