c# - Alert on gridview edit based on permission -
i have gridview edit option @ start of row. maintain seperate table called permission maintain user permissions. have 3 different types of permissions admin, leads, programmers. these 3 have access gridview. except admin if tries edit gridview on clicking edit option, need give alert this row has important validation , make sure make proper changes
.
when edit, action happen on table called application
. table has column called comments
. alert should happen when try edit rows comments column have these values in them.
manlog datas
funding approved
exported applications
my try far.
public bool isapplicationuser(string username) { return checkuser(username); } public static bool checkuser(string username) { string cs = configurationmanager.connectionstrings["connectionstring"].tostring(); datatable dt = new datatable(); using (sqlconnection connection = new sqlconnection(cs)) { sqlcommand command = new sqlcommand(); command.connection = connection; string strquery = "select * permissions appcode='nest' , userid = '" + username + "'"; sqlcommand cmd = new sqlcommand(strquery, connection); sqldataadapter da = new sqldataadapter(cmd); da.fill(dt); } if (dt.rows.count >= 1) return true; else return true; } protected void details_rowcommand(object sender, gridviewcommandeventargs e) { string currentuser = httpcontext.current.request.logonuseridentity.name; string str = configurationmanager.connectionstrings["connectionstring"].tostring(); string[] words = currentuser.split('\\'); currentuser = words[1]; bool appuser = isapplicationuser(currentuser); if (appuser) { dataset ds = new dataset(); using (sqlconnection connection = new sqlconnection(str)) { sqlcommand command = new sqlcommand(); command.connection = connection; string strquery = "select role_cd user_role appcode='pm' , userid = '" + currentuser + "'"; sqlcommand cmd = new sqlcommand(strquery, connection); sqldataadapter da = new sqldataadapter(cmd); da.fill(ds); } if (e.commandname.equals("edit") && ds.tables[0].rows[0]["role_cd"].tostring().trim() != "admin") { int index = convert.toint32(e.commandargument); gridview gvcurrentgrid = (gridview)sender; gridviewrow row = gvcurrentgrid.rows[index]; string strid = ((label)row.findcontrol("lblid")).text; string strappname = ((label)row.findcontrol("lblappname")).text; response.redirect("addapplication.aspx?id=" + strid + "&appname=" + strappname + "&edit=true"); } } }
kindly let me know if need add something. suggestions.
public static bool checkuseradminornot(your arguments) { string currentuser = httpcontext.current.request.logonuseridentity.name; string str = configurationmanager.connectionstrings["connectionstring"].tostring(); string[] words = currentuser.split('\\'); currentuser = words[1]; bool appuser = isapplicationuser(currentuser); if (appuser) { dataset ds = new dataset(); using (sqlconnection connection = new sqlconnection(str)) { sqlcommand command = new sqlcommand(); command.connection = connection; string strquery = "select role_cd user_role appcode='pm' , userid = '" + currentuser + "'"; sqlcommand cmd = new sqlcommand(strquery, connection); sqldataadapter da = new sqldataadapter(cmd); da.fill(ds); } if(user not admin) return string want.... } } }
after response in ajax use response , redirect page , pass value in url want...
Comments
Post a Comment