locked
Cannot show categories belonging to logged on user RRS feed

  • Question

  • User224181609 posted

    I am working on a membership-based site and have a page where the logged on user should be able to see the data he has put in a Categories table.  The screen shot (I hope to place below) shows a test page as rendered in my local browser.

    At the top a label is set up to show the UserID of the logged on user.

    Just below that is a Gridview that shows all existing categories and the UserID's of the users associated with those categories and the query that runs it. You can see that several of the categories are related to the UserID of the logged on user.

    However, below that you see that if I try to bring up a gridview of categories belonging to just the logged on user, I get none. The same with trying to show a drop-down list of just the categories.

    So the question:  I have worked (too many) hours trying to figure out why I can't manage to bring up just the data of the logged on user, when it is obviously present in the database.

    Here's the screenshot when the page is previewed in browser:

    screenshot

    The page  source code is:

    <form id="form1" runat="server">

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestCategoriesNoMaster.aspx.vb" Inherits="TestCategoriesNoMaster" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <p>
    The UserID of the logged on user is:&nbsp;
    <asp:Label ID="LblUserID" runat="server" Text="Label"></asp:Label>
    </p>
    <p>
    Here is a gridview of all the categories for the different users which runs off this query:</p>
    <p>
    &quot;SELECT [CategoryID], [Category], [User_ID] FROM [Categories] ORDER BY [User_ID]&quot;</p>
    <p>
    <asp:GridView ID="GVAllUsersCategories" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="SDSAllusersAndCategories">
    <Columns>
    <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" />
    <asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" />
    <asp:BoundField DataField="User_ID" HeaderText="User_ID" SortExpression="User_ID" />
    </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SDSAllusersAndCategories" runat="server" ConnectionString="<%$ ConnectionStrings:MyNumbersTrackerDBConnectionString %>" SelectCommand="SELECT [CategoryID], [Category], [User_ID] FROM [Categories] ORDER BY [User_ID]"></asp:SqlDataSource>
    </p>


    <div>
    <p>Below&nbsp; is a gridview where I am just trying to show the data of the logged on user which runs off this query below but shows no data:</p>
    <p>SELECT [CategoryID], [Category], [User_ID] FROM [Categories] WHERE ([User_ID] = @User_ID)</p>
    <p>
    <asp:GridView ID="GVCategoriesOfLoggedOnUser" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="SDSCategoriesOfLoggedOnUser" EmptyDataText="NO DATA RETURNED">
    <Columns>
    <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" />
    <asp:BoundField DataField="Category" HeaderText="Category" SortExpression="Category" />
    <asp:BoundField DataField="User_ID" HeaderText="User_ID" SortExpression="User_ID" />
    </Columns>
    </asp:GridView>
    </p>


    </div>

    <div>
    <br />
    When I create a dropdown list to show just the categories of the logged on user, it shows also no categories (it runs off the same query):<br />
    <br />
    SELECT [CategoryID], [Category], [User_ID] FROM [Categories] WHERE ([User_ID] = @User_ID)<br />


    <asp:DropDownList ID="DDLCategproesOfLoggedOnUser" runat="server" AutoPostBack="True" DataSourceID="SDSCategoriesOfLoggedOnUser" DataTextField="Category" DataValueField="CategoryID">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SDSCategoriesOfLoggedOnUser" runat="server" ConnectionString="<%$ ConnectionStrings:MyNumbersTrackerDBConnectionString %>" SelectCommand="SELECT [CategoryID], [Category], [User_ID] FROM [Categories] WHERE ([User_ID] = @User_ID)">
    <SelectParameters>
    <asp:Parameter DefaultValue="d239aecf-4b2c-413b-8421-26fea4ebd7f2" Name="User_ID" Type="Object" />
    </SelectParameters>
    </asp:SqlDataSource>

    </div>

    </form>
    </body>
    </html>

    </form>

    <form id="form1" runat="server">
    </form>
    Friday, June 22, 2018 2:05 AM

Answers

  • User224181609 posted

    OK, please ignore this thread. For some unknown reason everything is now working as it should, at least on the test page .  I have no idea why. Maybe some browser cache issue who knows!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 22, 2018 2:44 AM

All replies

  • User224181609 posted

    Slightly more information:  If I remove the Type="Object" term from the Parameter statement near the bottom of the page of source code, then the users data is returned as it should be. 

    But when I replace the parameter line with this (which would need to be done in practice instead of explicitly giving the UserID value):

    <SelectParameters>
    <asp:ControlParameter ControlID="LblUserID" Name="User_ID" PropertyName="Text" />
    </SelectParameters>

    the problem of no data being returned remains. Also, I should have mentioned, the single line of code running on page load is:

    LblUserID.Text = Membership.GetUser().ProviderUserKey.ToString()

    Friday, June 22, 2018 2:34 AM
  • User224181609 posted

    OK, please ignore this thread. For some unknown reason everything is now working as it should, at least on the test page .  I have no idea why. Maybe some browser cache issue who knows!!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 22, 2018 2:44 AM