Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone, I am doing a page where I am using drop down lists and pulling the data from a db, I have it pulling some fields but for some reason it wont pull the user logged in within the first drop down, it pulls the id associated with the project and also the email addresses... We are doing a rating page where a senior person can look at their team within the group and rate their skills out of 5, i.e their coding skills, team working etc..

The code below is for the asp.net front end page with the drop downs and connecting to the database...

ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="~/Registered Users/My Projects/MyProjectsMasterPage.master" AutoEventWireup="true" CodeFile="Ratings.aspx.cs" Inherits="Registered_Users_My_Projects_Ratings" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" Runat="Server">
    <h1>Project Manager Reviews Page</h1>
    <asp:Label ID="uname" runat="server" Text="" Visible="false"></asp:Label>
    <asp:Label ID="uid" runat="server" Text="" Visible="false"></asp:Label>
    <div>
        <asp:DropDownList ID="DropDownProjects" runat="server" DataSourceID="SqlDataSourceProject" 
            DataTextField="project_id" DataValueField="project_id" AutoPostBack="true" OnSelectedIndexChanged="ProjectSelected"></asp:DropDownList>

        <asp:SqlDataSource ID="SqlDataSourceProject" runat="server" ConnectionString="<%$ ConnectionStrings:ScrumString %>" 
        SelectCommand="SELECT project_title FROM projects INNER JOIN project_managers ON projects.project_id = project_managers.project_id INNER JOIN users ON project_managers.user_id = users.id WHERE user_id = @uid" OnSelecting="SqlDataSourceProject_Selecting">
            <SelectParameters>
                 <asp:Parameter Name="uid"/>
            </SelectParameters>
        </asp:SqlDataSource>


        <asp:DropDownList ID="DropDownListSprints" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SprintSelected" DataSourceID="SqlDataSourceSprints" DataTextField="project_id" DataValueField="project_id">
        </asp:DropDownList>

        <asp:SqlDataSource ID="SqlDataSourceSprints" runat="server" ConnectionString="<%$ ConnectionStrings:ScrumString %>" 
            SelectCommand="SELECT * FROM [sprints]"></asp:SqlDataSource>

        <asp:DropDownList ID="DropDownListUsers" runat="server" AutoPostBack="true" DataSourceID="SqlDataSourceUsers" OnSelectedIndexChanged="UserSelected" DataTextField="username" DataValueField="username">
        </asp:DropDownList>

        <asp:SqlDataSource ID="SqlDataSourceUsers" runat="server" ConnectionString="<%$ ConnectionStrings:ScrumString %>" 
            SelectCommand="SELECT [username] FROM [users]"></asp:SqlDataSource>

</div>
</asp:Content>



I have some basic C# code in the back end also

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Globalization;

public partial class Registered_Users_My_Projects_Ratings : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String userName = Session["UserLoggedOn"].ToString();
        uname.Text = userName;
        string connectionString = WebConfigurationManager.ConnectionStrings["ScrumString"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(connectionString);
        myConnection.Open();

        String userIDQuery = "SELECT id FROM users WHERE username= '" + userName + "'";
        SqlCommand cmd = new SqlCommand(userIDQuery, myConnection);
        String usrIDAsString = cmd.ExecuteScalar().ToString();
        Int32 uidresult = Convert.ToInt32(cmd.ExecuteScalar().ToString());
        uid.Text = Convert.ToString(uidresult);
        SqlDataSourceProject.SelectParameters.Add("@uid", uid.Text);

        myConnection.Close();


    }

    protected void ProjectSelected(object sender, EventArgs e)
    {

    }

    protected void SprintSelected(object sender, EventArgs e)
    {

    }



    protected void UserSelected(object sender, EventArgs e)
    {

    }

    protected void SqlDataSourceProject_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        
    }
}



Any help would be great if anyone could point out why the first drop down wont display anything, again we are trying to have the project manager assigned to the task here, then the id of the project and then the email/username of the person..
Posted
Comments
Ryan Doyle 30-Nov-15 11:15am    
Thanks for the comments Richard, I understand but im looking to get this working quickly at the moment, can you see any idea that is wrong?

That is because you have dropdown with...
HTML
DataTextField="project_id" DataValueField="project_id" 

But the SelectCommand does not select this column.
HTML
SelectCommand="SELECT project_title FROM Projects ....

So just add this colum to the select query.
 
Share this answer
 
C#
String userIDQuery = "SELECT id FROM users WHERE username= '" + userName + "'";


Should be

C#
var userIDQuery = "SELECT [id] FROM [users] WHERE [username] = " + userName + "";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900