display data for a particular logged in user (User.Identity.Name;)

hi, basically i have a database table with:

fileNo, fileName, fileSize, fileType, fileOwner etc

at the minute my grid view displays ALL files for every fileOwner, how does one filter this to only displaying the files which belong to a particular fileOwner who is logged in..

i.e. SELECT * FROM tblFile

      WHERE fileOwner = (User.Identity.Name)         -   to show files for a user who is logged in

 

how does one do this please?

 

thanks and regards

0
jules52
1/19/2009 5:35:26 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

8 Replies
971 Views

Similar Articles

[PageSpeed] 18

Hi,jules

U can Do like this

I am assuming that ur gridview is Using

sqldtsrc as id of its sqldatatsource

In aspx

<asp:SqlDataSource ID="sqldtsrc" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [tblFile] WHERE (fileOwner = ? )"

OnSelecting="sqldtsrc_Selecting">

<SelectParameters>

<asp:Parameter Name="fileOwner" Type="String" />

</SelectParameters>

</asp:SqlDataSource>

 

 

In code behind

 

protected void sqldtsrc_Selecting(object sender, SqlDataSourceSelectingEventArgs e)

{

e.Command.Parameters[
"fileOwner"].Value = this.User.Identity.Name;

}

 

 


RAGHAV

MVP ASP/ASP.Net Read My Blog


MARK THE POST AS ANSWER IF IT HELPS U.


"Success doesn't come to you…you go to it."--Marva Collins




"Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


0
raghav_khunger
1/19/2009 5:56:48 AM

...

0
jules52
1/19/2009 8:13:22 AM

oh cheers, my gridview is using

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"

 

SelectCommand="SELECT fileName, fileType, fileSize, fileOwner FROM aspnet_Files">

</asp:SqlDataSource>

 

so pass a parameter with the file owner as a string then, il try that!

0
jules52
1/19/2009 8:13:30 AM

ok i did this

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"

 

SelectCommand="SELECT fileName, fileType, fileSize, fileOwner FROM aspnet_Files WHERE (fileOwner = ? )"

 

OnSelecting="SqlDataSource1_Selecting">

 

<SelectParameters>

<asp:Parameter Name="fileOwner" Type="String" />

</SelectParameters>

</asp:SqlDataSource>

 

code behind:

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)

{

e.Command.Parameters[
"fileOwner"].Value = this.User.Identity.Name;

}

 

and got error:

Exception Details: System.IndexOutOfRangeException: An SqlParameter with ParameterName 'fileOwner' is not contained by this SqlParameterCollection.

Source Error:

Line 48:         {
Line 49: 
Line 50:             e.Command.Parameters["fileOwner"].Value = this.User.Identity.Name;
Line 51:         }
Line 52: 

what im i doing wrong?
0
jules52
1/19/2009 9:10:59 AM

 Hi,jules

 

jules52:
Exception Details: System.IndexOutOfRangeException: An SqlParameter with ParameterName 'fileOwner' is not contained by this SqlParameterCollection.

Try This

This Will work

e.Command.Parameters[0].Value = this.User.Identity.Name;


RAGHAV

MVP ASP/ASP.Net Read My Blog


MARK THE POST AS ANSWER IF IT HELPS U.


"Success doesn't come to you…you go to it."--Marva Collins




"Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


0
raghav_khunger
1/19/2009 9:22:47 AM

um.. now i get:

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '?'.

 

0
jules52
1/19/2009 9:33:48 AM

 Hi,jules

Try This

SelectCommand="SELECT fileName, fileType, fileSize, fileOwner FROM aspnet_Files WHERE fileOwner = @fileOwner"

 


RAGHAV

MVP ASP/ASP.Net Read My Blog


MARK THE POST AS ANSWER IF IT HELPS U.


"Success doesn't come to you…you go to it."--Marva Collins




"Success does not come to those who wait . . . and it does not wait for anyone to come to it." Anonymous


0
raghav_khunger
1/19/2009 9:53:42 AM
raghav_khunger, thanks very much for your help - that worked successfully!
0
jules52
1/19/2009 9:57:52 AM
Reply:

Similar Artilces:

User.Identity.Name swaps with other logged in users
I seem to be having a problem with User.Identity.Name, never given me any problems in the past, however, i've just put a site live and for some reason, every now and then the value of Name changes to that of another user logged into the system! However, it's only for one page view! Once you view any page again, the information resets back to the original and correct user (i.e. value in .Name). The only one bit of information i could see on google about this related to worker processes recycling.Is this possible? Could the worker process recycling end up with users being confused? I...

Problem in getting logged in user Name for ASPX page with (even with this.User.Identity.Name)
Hi  friends,  I am creating an application that takes current logged in user and displays on the page itself. for this I am getting the user name in PageLoad function by using this.User.Identity.Name and then storing the value in a hidden variable for aspx page. I am using this hidden  variable to display the name of the user. I am using Windows authentication for this. Now problem that I am getting is that when multiple user launch the application from different machine and if they click simultaneously, name of one user appears on the paged displayed on the machine of ot...

difference between HttpContext.Current.User.Identity.Name and User.Identity.Name
Q1. what is the difference between 1. HttpContext.Current.User.Identity.Name;and 2. User.Identity.Name Q2.i'm using asp.net 2.0. i'm using the following code to authenticate FormsAuthentication.RedirectFromLoginPage(strEMail, false); Response.Redirect("web/ra.aspx"); my main web.config has <authentication mode="Forms">      <forms          name=".ASPXAUTH"          loginUrl="back.htm"          protection="All" &n...

Query logged in user
First, the obliquity I am a newbie to ASP! I have Googled for while now but cannot seem find a solution to my problem. I am trying to display the details of the logged in user (UserName). Below is my code but nothing is displayed by the query. The Label ID="lblIdentity" does display the logged on users username correctly . Any help would be appreciated.   ASPX page…     <asp:Label ID="lblIdentity" runat="server" Style="z-index: 104; left: 14px; position: absolute;             top: 28px" Text="Label">...

Logged in user displays user specific data from database
Hi there - I am fairly new to ASP.NET and am hoping for some guidance here ... I am building an application for manages to track employees as the employee leaves the business.  Basically there are processes a line manager is required to complete and I want the manager to enter completion dates when those processes have been completed. I have gotten as far as successfully creating the login/membership controls.  The user (line manager) logs in and is then redirected to the correct page and thats fine.  However, I then want for the user to see records from a dat...

Separting the User name from the Machine name in User.Identity.Name
string userNameWithMachineName = User.Identity.Name; string userNameWithoutMachineName = System.IO.Path.GetFileName(userNameWithMachineName); HighOnCodingWanna get high! ...

How do I display data in a datagrid specific to the logged in user using the User ID
Hi, I've got a table that holds user details (such as age, location etc). This table is linked to a user logon details table by the UserID column. How do I get a datagrid to display the logged on users details?  Everything I've read so far uses Username but username isn't a column in my UserDetails table. I've tried SELECT all from the user details table and using UserID as a session parameter but the datagrid doesn't display so I'm doing something very wrong I think. The sql statement looks like this:  SELECT UserID, FirstName, Surname, Telephone, Sect...

Insert Page.User.Identity.Name (User Domain and username) into SQL
Hi there I'm trying to get the windows username into SQL for an Intranet application I'm building. I can get the information I want onto a text labe by binding it to <% Page.User.Identity.Name %>, but how can a get it into my sql insert command. I've tried putting it into the Parameters for the insert as <asp:Parameter Name="ByUsername" DefaultValue = <% Page.User.Identity.Name %> /> but that is inserting "<% Page.User.Identity.Name %>" into the database. Although I'm a beginner I don't have any books yet - but study well with google so even a clue...

Can not get user name from HttpContext.Current.User.Identity.Name
Hi All; I have tried to use HttpContext.Current.User.Identity.Name to get window user account. However, from debugger, for a long time ago I saw my window user name. But now, I did not see my window user name (from debugger) with the same code and same function call. Please help. Was I doing something wrong? Or any special settings on web.config/machine.config or project to make it work??? I'm stuck Thanks a lot well, you have to have windows integrated authentiction enabled in IIS, IIRC.RTFM - straight talk for web developers. Unmoderated, uncensored, occasionally unre...

User.Identity.Name returns email address instead of user name
I have modified the login control so that the user logs in using their email instead of their user name. Here is my code:Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate Dim email As String = Login1.UserNameDim userName As String = Membership.GetUserNameByEmail(Login1.UserName)Dim userInfo As AdditionalUserInfo = New AdditionalUserInfo   If Membership.ValidateUser(userName, Login1.Password) = True ThenDim isFirstTime As Boolean = userInfo.GetUserInfo(userName).IsFirstTime If isFirstTi...

What has to happen after login before Page.User.Identity.Name contains the user name?
I am using Membership Services in my new ASP.NET 3.5 app. I want to redirect the user to a page where he can enter various personal details if he has not yet done this. I put some VB.NET code in the LoggedIn event for my Login control that depends on the availability of the current user name in Page.User.Identity.Name but this reference is Nothing at this stage in the process. Page.User.Identity.Name works fine on other pages. When exactly is Page.User.Identity.Name loaded with the name of the current user?David   The authentication process hapen like this... 1-User request a secur...

how to get user data from a logged in user
I have the standard login controls from ASP.NET 2.0 on my site. Now i've added a id field from another table to the aspnet_users table as FK. Now i want to use this ID (if the user is logged in) to populate my datagrid. How can i get this ID?  Erik    Check below link Work With Membership API HCHaissam Abdul MalakMCAD.NET| Blog | Hi Please follow the link http://forums.asp.net/thread/1702250.aspx and raise the problem you've meet :) Good luckBest RegardsXiaoYong DaiMicrosoft Online Community SupportPlease remember to click “Mark as Answer” on the ...

User Control
I am trying to convert my aspx page that has all my graphics into a header user control, in the page I reference the username that is logged into the site.  I am using the User.Identity.Name function but it tells me that User is not identifited.  This worked just fine before I moved it to the ascx page. Anyone have any ideas? Thanks Craig In a user control or custom control your will need to use either:Page.User.Identity.Name orHttpContent.Current.User.Identity.Name If using the latter, don't forget to import the System.Web namespaceBill, WESNet Designs...

User.Identity.Name in User Control
What namespace do I have to include in my User Control code behind to be able to access the Forms Login User.Identity.Name information? Thanks!I haven't failed, I've found 10,000 ways that don't work System and System.Web.UI. Here's a sample of a user control retrieving User.Identity.Name: using System; using System.Web.UI; public class MyClass: Page { public void Page_Load(Object Source, EventArgs e) { Response.Write("User.Identity.Name=" + User.Identity.Name); } } Thanks lauraThis posting is provided "AS IS"...

Web resources about - display data for a particular logged in user (User.Identity.Name;) - asp.net.sql-datasource

'He was always funny': Conan remembers David Bowie with a touching montage
During Monday's episode of Conan , the late-night comedian paid tribute to David Bowie — not as the musician, but as the man "People are remembering ...

First Read's Morning Clips: Trump, Clinton Still Lead
NBCNews.com First Read's Morning Clips: Trump, Clinton Still Lead NBCNews.com OFF TO THE RACES: Trump, Clinton still lead. Our latest NBC ...

In his final State of the Union address, Obama seeks to stay relevant
Los Angeles Times In his final State of the Union address, Obama seeks to stay relevant Los Angeles Times President Obama delivers his State ...

Ricky Gervais posts defiant Twitter rant about Caitlyn Jenner joke
LONDON - Ricky Gervais is definitely not one to hold his tongue. Gervais hosted the Golden Globes on Sunday night using his opening monologue ...

How to install iOS 9.3 and get Night Shift on your iPhone without a developer account
Since Apple first released iOS 9 back in September last year, the company's subsequent software updates have mostly been about housekeeping. ...


Microsoft's plan to use TV to bring internet to India could have hit a roadblock
Microsoft's plan to bring the internet to India using TV airwaves may have hit a roadblock, according to a report from The Economic Times . ...

Islamic State Claims Responsibility for Pair of Iraq Attacks
Wall Street Journal Islamic State Claims Responsibility for Pair of Iraq Attacks Wall Street Journal BAGHDAD—Islamic State claimed responsibility ...

HTC Vive’s year of uncertainty
ANALYSIS: HTC’s Vive VR, Facebook-owned Oculus Rift, and Playstation VR are the three big virtual reality headsets from major tech companies ...

Explosion kills 10 people near popular tourist attraction in Istanbul
An explosion in the historic district of Sultanahmet, close to the Blue Mosque, in Istanbul, has left 10 dead and at least 15 others wounded, ...

Resources last updated: 1/12/2016 3:12:22 PM