您的位置:首页 > 其它

获取GridView中TemplatedField中LinkButton命令的当前行

2010-03-03 13:59 351 查看
在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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐