 |
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

September 9th, 2014, 12:44 PM
|
|
Authorized User
|
|
Join Date: Aug 2014
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Howto show only those gridview or listview rows where emailaddress column matches log
Even though I read the outstanding "Beginning ASP.NET 4.5.1: in C# and VB" book, I'm still wondering if I may have some assistance with this question (still a newbie at writing code in the code behind):
I want to compare the logged in user's loginname (the same as their email address) and pull up the row(s) in the table that have the matching value in the studentemail column. I tried hard coding a value in the code behind to test and it works. I don't know how to generalize it though (ASP.NET newbie). Here's the code in the code behind:
Code:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Session("StudentEmail") = "[email protected]"
End Sub
End Class
Table has a column named studentemail that stores same string as loginname. What I want to happen is for each student to only see his own grade records and no one else's. The rows in the gridview are downloadable files, each containing a report of the student's own information. I have the part about downloading the files worked out but right now each student would see all students' reports but I want them to see their own only.
Thanks!
|
|

September 9th, 2014, 01:25 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
|
|

September 9th, 2014, 02:30 PM
|
|
Authorized User
|
|
Join Date: Aug 2014
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Thanks! I'll use this and I appreciate your help.
|
|

September 9th, 2014, 09:27 PM
|
|
Authorized User
|
|
Join Date: Aug 2014
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Hello again, I have another related question: In the example the users add rows themselves. In my website the users won't add any data, a site(non-technical) administrator will. Please tell me your recommendation for how I can let this admin select the users who can see a given report? This is separate from what I was asking in my original question, but related. Sometimes an admin will want to upload many files that will have the intended student's name on them so that they can be shown to each student according to his username.
The next scenario/need is to send some types of files to a subset of students. The endusers told me that I should make checkboxes for each student but I know that wouldn't be a good idea because there are at least two thousand students. I am storing files in the database table. So far I can filter for public versus private student reports but that was just a first step for me to see if I could get that working. The real needs are to be able to 1)show each student his own report and 2)to allow the admin to select some variable number of students to send a separate, less private report to, 3)they also want to show a third type of report to all students but I have this last, easier case working.
Thanks!
|
|

September 10th, 2014, 05:51 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Take a look at System.Web.Security.Membership.GetAllUsers() ( http://msdn.microsoft.com/en-us/libr...vs.110%29.aspx) to retrieve a full list of all users. The Membership class has other methods to filter the list of users by name or e-mail. Alternatively, you can use EF to query all users from the database.
Not sure what you're asking in the second part of your question so I can't help there.
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

September 10th, 2014, 08:56 AM
|
|
Authorized User
|
|
Join Date: Aug 2014
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Thanks again, I will look into using System.Web.Security.Membership.GetAllUsers(). In the second part I am asking if there's a way that someone can upload a report(file) to the database and specify that there are anywhere from say, 2 to n recipients who should be able to view the report when they log in. Where n is any number between 2 and (the total number of loginIDs minus 1). There will be at least 2000 students to start.
The selection of the subset of userIDs will not be by anything that I can add a column in the database table to accommodate. The person who chooses the members of the subset wants to be able to select those who can see a report by selecting them by checking boxes or selecting them from a list. If I added two thousand checkboxes to a web form that would be the biggest form I've ever seen.
Have you ever had to do anything like this? Do you have a suggestion?
Thank you very much for all your help so far!
|
|

September 10th, 2014, 09:23 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You somehow need to build a filter to find the associated records and select them. You can use LINQ for that to take user input (name, e-mail address, department, whatever) and query the database. Then you could let your user select some or all of the record (using checkboxes as you pointed out). This gives the unique IDs of all users. You could then insert data in a junction table that links each report to all of the users. E.g.
Code:
ReportId UserId
1 1
1 2
1 3
2 1
2 4
Hope this helps,
Imar
Last edited by Imar; September 10th, 2014 at 09:42 AM..
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

September 10th, 2014, 10:23 AM
|
|
Authorized User
|
|
Join Date: Aug 2014
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Thanks for your wisdom and fast response. So if I have 2000+ students that an "administrator" could select I should really have 2000+ checkboxes on a form?
I was given a project that I'm not qualified to do in a very short period of time (I'm not a programmer) so I made the conscious choice to continue to work with SqlDatasource (I am a DBA) until I get this project done by the deadline. I realize that the student to reports relationship is many-to-many, which the entity-relationship model handles well if you just have the primary keys to each of the tables in the junction table.
Do you think this problem I've presented can be solved using the "old school" SqlDatasource control? I've asked for help earlier on another board but no one has any ideas after a few days. There must be an elegant way to do this but I cannot think of it. In any case, thanks for your expertise so far!
P.S. I found today that I can't use System.Web.Security.Membership.GetAllUsers() because simple membership does have the GetAllUsers method (I'm using the ASP.NET Webserver Administration Tool to configure users, roles, and (sometimes)directory permissions.
Last edited by DatabaseGoddess; September 10th, 2014 at 07:51 PM..
|
|

September 12th, 2014, 04:38 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
No, I don't think you should have 2000 check boxes in a form. Instead, you should build some query UI that lets you filter the users based on some criteria (if applicable) and then insert the data in the junction table at the server. Hard to say how you can build that UI as I don't know what your requirements and search criteria look like.
The simple provider should also have a GetAllUsers method: http://msdn.microsoft.com/en-us/libr...vs.111%29.aspx
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

September 12th, 2014, 05:44 PM
|
|
Authorized User
|
|
Join Date: Aug 2014
Posts: 16
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Training my stakeholders to be specific, at least sometimes
Quote:
Originally Posted by Imar
No, I don't think you should have 2000 check boxes in a form. Instead, you should build some query UI that lets you filter the users based on some criteria (if applicable) and then insert the data in the junction table at the server. Hard to say how you can build that UI as I don't know what your requirements and search criteria look like.
The simple provider should also have a GetAllUsers method: http://msdn.microsoft.com/en-us/libr...vs.111%29.aspx
Cheers,
Imar
|
Thanks for replying, I appreciate it. I have a problem in that the stakeholders of this project say they want to be able to select multiple physicians not based on anything quantifiable. So they might want to randomly pick 26 of the 2000m (they hope soon there will me many more than 2000). These stakeholders are nontechnical and expect magic. They believe that I should be able to figure out how to allow them to do that. They've actually said that's part of my job to anticipate what they want. Often I can anticipate but in cases like this I cannot.
Because I have been unable to pin them down after quite a few tries, I may just present them with a drop down of all physicians and allow them to select. This is an aversive user experience but maybe it will spark more details from them about how they would select a subgroup, at which time I could code something better.
I think I should use listbox to allow multiple selection. Does that sound ok to you?
Thanks!
|
|
 |
|