在GridView中添加一模板列 编辑该模板列中LinkButton的Command事件。 添加如下代码: protected void lbtnResetPwd_Command(object sender, CommandEventArgs e) { //获取RowIndex LinkButton lb = (LinkButton)sender; GridViewRow row = (GridViewRow)lb.Parent.Parent; //DataControlFieldCell dcf = (DataControlFieldCell)lb.Parent; //GridViewRow gvr = (GridViewRow)dcf.Parent; //gvUserList.SelectedIndex = gvr.RowIndex; gvUserList.SelectedIndex = row.RowIndex; string initPwd = ConfigurationManager.AppSettings["InitPassword"].ToString(); int passwordformat = Convert.ToInt32(ConfigurationManager.AppSettings["PasswordFormat"].ToString()); string newsalt = CommonUtils.GenerateRandomString(6, StringMode.Mix); string newpassword = CommonUtils.EncryptString(initPwd,passwordformat,newsalt); string username = row.Cells[1].Text; int userid = Convert.ToInt32(row.Cells[0].Text); if (UserBLL.ResetPassword(userid, newpassword, passwordformat, newsalt)) lblUserMsg.Text = "用户"+ username + "的密码已重置!"; else lblUserMsg.Text = "用户" + username + "的密码重置失败!"; } 方法二: 直接使用CLICK事件的代码: protected void lbtnViewRole_Click(object sender, EventArgs e) { int rowIndex = ((GridViewRow)((LinkButton)sender).NamingContainer).RowIndex; RoleModel role = RoleBLL.GetRoleInfo(Int32.Parse(gvRoleList.Rows[rowIndex].Cells[0].Text)); txtRoleNameEdit.Text = role.RoleName; txtRoleDescEdit.Text = role.RoleDesc; cbIsAuth.Checked = role.IsUser; cbIsSysEdit.Checked = role.IsSystem; }