Get data based on UserName (ASP)

Last edited:
Strange, the reason I ask this is because a few posts up you posted code form your Page_Load event which is in VB, then you posted code from the class ProfileCommon which is in C#.

The code from the class is autogenerated, so somewhere it must think that you are using C#.
 
Strange, the reason I ask this is because a few posts up you posted code form your Page_Load event which is in VB, then you posted code from the class ProfileCommon which is in C#.

The code from the class is autogenerated, so somewhere it must think that you are using C#.


I've without a doubt created the site and selected Visual Basic.

Really getting annoyed now and i've got no idea what to do.
 
Here is the example I did before to test it out, just put it up on my web host.

example.zip

You will need to delete the database and change the connections to your databases. Also it includes DAL and BLL, you will need to change the DALs, but not so much the BLL.

If you have any problems post back, and I'll try and help.
 
Cheers i'll check it out at home.

Someone from the ASP.net forum has suggested doing it this way, if you don't mind taking a look i'm not too sure on one part of what he wants me to do, but it does look otherwise fairly simple.

Simple, within the ObjectDataSource.Selecting event, set your UserName parameter like so:

Code:
protected void ObjectDataSource1_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
	e.InputParameters["UserName"] = this.User.Identity.Name;
}

Not seeing your code, it's a little tough to see exactly what you're doing. However, if your using an ObjectDataSource, I'm assuming you have a Parameter set up declaratively within your ObjectDataSource like so:

Code:
<asp:objectdatasource id="ObjectDataSource1" runat="server" onselecting="ObjectDataSource1_Selecting">
	<selectparameters>
		<asp:parameter name="Username" type="String" />
	</selectparameters>
</asp:objectdatasource>

Then, with the Selecting event declared in the ObjectDataSource as above, the Selecting event will fire right before the code within your select method is fired. In this event, we extract the currently logged-in user's username from the Page's IPrincipal object. Your Parameter is then set to this value. With this, your select method will now be passed the appropriate username which can be used to inject into your SQL query or added as a parameter.

I'm not sure where to put the first bit of code really or what he means.
 
Basically he's suggesting that you hardcode the parameter into the object data source of the select statement, the one that you use to populate the gridview.

Go into the design view, select the object data source and select the 'Selecting' event from the event tab in the properties.

He has posted C# code, in VB it will be slightly different but similar.
Here goes my C# to VB conversion skillz ;)
Although I'm not sure that it'll be 100% correct :o

Code:
Protected Sub ObjectDataSource1_Selecting(ByVal sender As object, ByVal e As ObjectDataSourceSelectingEventArgs)
     e.InputParameters("UserName") = Me.User.Identity.Name
End Sub
 
Working!

You are indeed a legend, leg-end and allround hero. You've helped me loads with this I can't thank you enough.
 
Back
Top Bottom