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...
<%@ 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
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..