I have a StudentGrades table which I want to give access to users in the Student's role. So when a student accesses the Student Grades they will only see their own grades.
are you going to display the studentGrageds data ?, you have keep the user role in role management methods...pleaes have a look in to this article, which will clearly explain how to implement it.
Why don't you simply show (via menu) the same GridView that you might be using to display the whole set of data but putting some kind of constraint in the "where" part of the DataSource ... there you will have only the records that belong to that kind of
user profile .... ?
Just pass as parameteres the info you get from the login user screen ... piece of cake, isn't it?
Member
18 Points
187 Posts
How to limit rows by user role
Apr 11, 2013 05:27 PM|mr41971|LINK
I have a StudentGrades table which I want to give access to users in the Student's role. So when a student accesses the Student Grades they will only see their own grades.
Contributor
4732 Points
1001 Posts
Re: How to limit rows by user role
Apr 11, 2013 05:32 PM|ninianne98|LINK
a good bit will depend on your security model - such as group management and identification of current user and the current user's ID
pseudo code:
string sSQL ="";
if (Roles.IsUserInRole("student group" ) {
sSQL = "select * from grades where studentid = " + userid;
}
if (Roles.IsUserInRole("teacher group") ) {
sSQL = "select * from grades where teacherid = " + userid;
}
then run the SQL to get the restricted list
or
List<Grades> grades = new List<Grades>();
if (Roles.IsUserInRole("student group" ) {
grades = (from g in db.gradeTable
where g.studentid= userid
select g).ToList();
}
if (Roles.IsUserInRole("teacher group") ) {
grades = (from g in db.gradeTable
where g.teacherid = userid
select g).ToList();
}
and then bind to grades.
Mark as Answer if this response was helpful.
Contributor
4954 Points
1726 Posts
Re: How to limit rows by user role
Apr 11, 2013 06:46 PM|thirumaran007|LINK
are you going to display the studentGrageds data ?, you have keep the user role in role management methods...pleaes have a look in to this article, which will clearly explain how to implement it.
http://msdn.microsoft.com/en-us/library/5k850zwb(v=vs.100).aspx
With Friendly,
Thirumaran
Member
18 Points
187 Posts
Re: How to limit rows by user role
Apr 12, 2013 09:28 AM|mr41971|LINK
Sorry I should have added in a dynamic data project.
Member
242 Points
480 Posts
Re: How to limit rows by user role
Apr 13, 2013 11:12 AM|klca|LINK
Hi,
Why don't you simply show (via menu) the same GridView that you might be using to display the whole set of data but putting some kind of constraint in the "where" part of the DataSource ... there you will have only the records that belong to that kind of user profile .... ?
Just pass as parameteres the info you get from the login user screen ... piece of cake, isn't it?
Carlos N. Porras
(El Salvador)