我似乎无法让我的下拉列表填充.. [英] I cant seem to get my drop down list to populate..

查看:52
本文介绍了我似乎无法让我的下拉列表填充..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在做一个页面,我正在使用下拉列表并从数据库中提取数据,我已经拉了一些字段但是由于某种原因它不会拉用户在第一个下拉列表中登录,它拉出与项目相关联的ID以及电子邮件地址......我们正在进行评级页面,高级人员可以在组中查看他们的团队并评估他们的技能,包括他们的编码技能,团队合作等。 。



以下代码适用于带有下拉菜单并连接到数据库的asp.net前端页面...



 <%@    < span class =code-leadattribute> Page    标题  =    语言  =  C#    MasterPageFile   = 〜/注册用户/我的项目/ MyProjectsMasterPage.master    AutoEventWireup   =  true    CodeFile   =  Ratings.aspx.cs   继承  =  Registered_Users_My_Projects_Ratings   %>  

< asp:内容 ID = Content1 ContentPlaceHolderID = head Runat = 服务器 >
< / asp:Content >
< asp:内容 ID = Content2 ContentPlaceHolderID = MainContentPlaceHolder Runat = 服务器 >
< h1 > 项目经理评论页< / h1 >
< asp:标签 ID = uname runat = 服务器 文字 = 可见 = false > < / asp:Label >
< asp:Label ID = uid runat = server 文字 = 可见 = 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 < span class =code-attribute> 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 :参数 名称 = uid / >
< / SelectParameters >
< / asp:SqlDataSource >


< asp:DropDownList < span class =code-attribute>
ID = DropDownListSprints runat = server AutoPostBack = true OnSelectedIndexChanged = SprintSelected DataSourceID = SqlDataSourceSprints DataTextField = project_id DataValueField = project_id >
< / asp:DropDownList >

< asp:SqlDataSource ID = SqlDataSourceSprints runat = 服务器 ConnectionString = <% $ ConnectionStrings: ScrumString %>

SelectCommand = SELECT * FROM [sprints] > < span class =code-keyword><
/ asp:SqlDataSource >

< asp:Drop DownList ID = DropDownListUsers runat = server AutoPostBack = true DataSourceID = SqlDataSourceUsers < span class =code-attribute> OnSelectedIndexChanged = UserSelected DataTextField = userna我 DataValueField = 用户名 >
< / asp:DropDownList >

< asp:SqlDataSource ID = SqlDataSourceUsers runat = server ConnectionString = <% $ Connec tionStrings:ScrumString %>

SelectCommand = SELECT [用户名] FROM [用户] > < / asp:SqlDataSource >

< / div >
< / asp:Content >







我后端还有一些基本的C#代码



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;

使用 System.IO;
使用 System.Data;
使用 System.Data.SqlClient;
使用 System.Web.Configuration;
使用 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();

字符串 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();


}

受保护 void ProjectSelected( object sender,EventArgs e)
{

}

protected void SprintSelected( object sender,EventArgs e)
{

}



protected void UserSelected( object sender,EventArgs e)
{

}

$ b protected void SqlDataSourceProject_Selecting( object sender, SqlDataSourceSelectingEventArgs e)
{

}
}







如果有人能指出f为什么,任何帮助都会很棒irst下拉不会显示任何内容,我们再次尝试将项目经理分配到此处的任务,然后是项目的ID,然后是该人的电子邮件/用户名..

解决方案

ConnectionStrings:ScrumString %>

SelectCommand = SELECT project_title FROM projects INNER JOIN project_managers ON projects.project_id = project_managers.project_id INNER在project_managers上加入用户。 user_id = users.id WHERE user_id = @uid OnSelecting = SqlDataSourceProject_Selecting >
< SelectParameters >
< asp:参数 名称 = uid / >
< / SelectParameters >
< / ASP:S qlDataSource >


< < span class =code-leadattribute> asp:DropDownList ID = DropDownListSprints runat = server AutoPostBack = true < span class =code-attribute> OnSelectedIndexChanged = SprintSelected DataSourceID = SqlDataSourceSp rints 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 < span class =code-attribute> DataSourceID = SqlDataSourceUsers OnSelecte dIndexChanged = UserSelected DataTextField = 用户名 DataValueField = 用户名 >
< / asp:DropDownList >

< asp:SqlDataSource ID < span class =code-keyword> = SqlDataSourceUsers runat = server ConnectionString = <%

ConnectionStrings:ScrumString %>

SelectCommand = SELECT [username] FROM [users] > < / asp:SqlDataSource >

< / div >
< / asp:Content >







我后端还有一些基本的C#代码



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;

使用 System.IO;
使用 System.Data;
使用 System.Data.SqlClient;
使用 System.Web.Configuration;
使用 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();

字符串 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();


}

受保护 void ProjectSelected( object sender,EventArgs e)
{

}

protected void SprintSelected( object sender,EventArgs e)
{

}



protected void UserSelected( object sender,EventArgs e)
{

}

$ b protected void SqlDataSourceProject_Selecting( object sender, SqlDataSourceSelectingEventArgs e)
{

}
}







如果有人能指出f为什么,任何帮助都会很棒irst 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..


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

解决方案

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


这篇关于我似乎无法让我的下拉列表填充..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆