我的下拉列表存在问题,填充其中一个字段。基本上,它意味着拉入登录的用户或链接到某个项目的用户。
我在页面上有3个下拉菜单,其中2个从db返回结果,一个剂量,我不知道为什么,它可能并且很可能是sql命令或c#后端代码中的内容,如果我粘贴代码,如果有人可以帮助我找出那个很棒的问题。
<%@ 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>
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();
}
很抱歉,如果代码没有很好地呈现,我不确定如何正确地形成它。
任何帮助都会很棒......
谢谢