<asp:TemplateField HeaderText="操作" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lbtnPhoneHide" runat="server" CommandArgument='<%# Eval("id") %>'
CommandName="1" Text="操作"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
一、
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
try//因为gridview一行中既有Button也有LinkButton,而下面获取gvrow需要用到,所以用try,要不然点击Button时会报错无法转换
{
GridViewRow gvrow = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);//获取被点击的linkButton所在的GridViewRow
int i = gvrow.RowIndex;//获取到行索引 RowIndex
if ("1" == e.CommandName)
{
long longPhoneId = Convert.ToInt64(e.CommandArgument);
Label lbPhone = gvXyPhone.Rows[i].FindControl("lbPhoneG") as Label;
}
}
catch (Exception)
{
}
}
二、
在 linkbutton中增加 OnClick="lbtnPhoneHide_Click" 事件
protected void lbtnPhoneHide_Click(object sender, EventArgs e)
{
long longPhoneId = Convert.ToInt64(((LinkButton)sender).CommandArgument);
}