Tuesday, February 14, 2012

database type question

Hi everyone, I am trying to create a page on my website that will be unique depending on the logged on user. Basically, I have a aspnet_User table, a Team table, and a Player table. What I am trying to do is make a datagridview that is editable, but only showing the 'players' from the player table that is associated to that member. I have tried to set a relation between the tables in a dataset, but that only got me so far before I got stuck, and I've also tried to do it making a view between the three tables before I got stuck. My tables look like this:

'aspnet_Users' has a
User ID
User Name
along with the other column associated with this table

'Team' has a
Team ID
Team Name
User Name

'Player' has a
Player Name
Team ID
Player Rating
Class

What I would really like to be able to do, is when the webpage is loaded, the datagridview reads the User Name from the aspnet_User table and matches it to the corresponding Team ID in the Team Table and then filters the 'Player' table to only show players with the corresponding Team ID. I have been stuck on this for two weeks now and it is driving me crazy. I seem to get a breakthrough only to get stuck again. Please Help!!! If you need any more info from me, please let me know!

Use a stored procedure as your datasource for your GV. Pass the teamID in as a parameter.

|||

What you need is a gridview that is populated by a parameterised query, like so:

SELECT
PlayerName
FROM
Team INNER JOIN Player ON Team.TeamID = Player.TeamID INNER JOIN
aspnet_users ON Team.UserName = aspnet_users.UserName
WHERE
aspnet_users.UserName @.UserName

Set this at the SQL for the Gridview and then the @.UserName parameter's value is Context.User.Identity.Name. Context.User.Identity.Name is the username of the currently logged in user.

|||

Ok, now, stupid question

By gridview, you mean make a view from the database right?

I then put in the three tables, make my relationship and add in the sql statement you just provided me, correct?

Then where, and/or how do I set the parameter's value?

I really appreciate the help guys, I think this is starting to make sense!

|||

Ok,

I made my gridview with the 3 tables and tried to insert the sql statement you gave me and it tells me this

incorrect syntax near @.UserName

|||

Here's a good thread for you:

http://forums.asp.net/p/991273/1317881.aspx

|||

First off, thank everyone so far for all your help.

I think I have everything set up the way it is supposed to be. When I test the query and type in 'ryan', one of my UserNames it returns the correct team. if I try to type in a wrong name that does not exist (i even put a name in the Team table and not the username table, and it didn't pull, so i think it is pulling from the right table)

Here's the problem. when i go to web page preview, no datagridview shows up on my page, nothing, nada, zip...like it doesn't exist.

what do i have wrong?

|||

Ah. Try a databind for your grid on the GridView_PreRender event.

|||

So are you typing in a username in a textbox and then clicking a button? On the button click event are you calling the DataBind method on your gridview?

All you need to do is call this in your PageLoad event after setting the textbox.text to the name of the currently logged in user. Do you follow?

|||

I've got a login box that i inserted through the ide. in the code it doesn't give a pageload reference. i remember doing a pageload on a button click with visual basic, but i'm not sure how to work in into this.

<asp:LoginID="Login1"runat="server"BackColor="#EFF3FB"BorderColor="#B5C7DE"BorderPadding="4"

BorderStyle="Solid"BorderWidth="1px"Font-Names="Verdana"Font-Size="0.8em"

ForeColor="#333333"DestinationPageUrl="index.aspx">

<TitleTextStyleBackColor="#507CD1"Font-Bold="True"Font-Size="0.9em"ForeColor="White"/>

<InstructionTextStyleFont-Italic="True"ForeColor="Black"/>

<TextBoxStyleFont-Size="0.8em"/>

<LoginButtonStyleBackColor="White"BorderColor="#507CD1"BorderStyle="Solid"BorderWidth="1px"

Font-Names="Verdana"Font-Size="0.8em"ForeColor="#284E98"/>

</asp:Login>

It gives me a destination url, but thats about it. does the code need to go into here somewhere?

btw, thank you for your help and patience

|||

Where's your codebehind?

<%@. Page Language="C#"
MasterPageFile="~/MasterPage.master"
AutoEventWireup="true"
EnableEventValidation="false"
Inherits="blah.blah.blah"
Title="balh : blah"
Codebehind="blah.aspx.cs"
Description="blah."
Theme="blah"
EnableTheming="true"
%>

Then you access your page_load in the aspx.cs file.|||

can you give me an example?

btw, it tells me that codebehind is no longer used

|||

ummm. I'm using it. Is there something someone needs to tell me?

Are you using VS2005? When you start a project in C#, select Web and you'll get a aspx and aspx.cs (codebehind) pages. If you are using VB, you may need to wire up the codebehind manually, I don't know. Does anyone out there know about codebehind being obsoleted? AM I CODEBEHIND THE CURVE!?!?!?!Big Smile

|||

sorry, i'm using vb not c#, my files are aspx.vb

its telling me that it is still compatible with asp.net 2.0, but now they would 'rather' you use the codefile and the inherits property

ok, i can get into the aspx.vb files and it gives me

PartialClass Teams_westerville

Inherits System.Web.UI.Page

EndClass

i put the page_load into here, right?

I'm at work right now, going to try it when i get home

|||

Must be a VB thing. My ASP.Net 2.0 C# page here has a codebehind and an inherits. I'm inheriting what appears to be the namespace... but it compiles. so it must be right, right? Smile