灌装从SQL错误下拉 [英] Filling the dropdown from sql bug

查看:135
本文介绍了灌装从SQL错误下拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,人们一直在试图填补使用SQL命令下拉,直到这么好,当我点击下拉它显示了所有项目,但是当我尝试点击某个项目在下拉菜单中它总是返回在下拉列表中第一项....遵循codeS,我想要做的就是从下拉列表中选择的值和物品,并将其保存以供将来使用的标签上。

我AP preciate一切可能的支持,

 保护小组的Page_Load(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手Me.Load
    utilizador.Text = Me.Context.User.Identity.Name
    如果(不Page.IsPostBack)然后
        escolhePerfil()
    万一    DropDownPerfil.DataBind()
    lbperfil2.Text = DropDownPerfil.SelectedItem.Text
    lbnome.Text = DropDownPerfil.SelectedValue
结束小组
功能escolhePerfil()为布尔
    昏暗CONNSTRING作为字符串=数据源= 10.2.24.17;坚持安全信息= TRUE;用户ID = SA;密码= $ Pr0dUn1C0 QL;数据库= ePrimavera
    昏暗SQLDATA作为新System.Data.SqlClient.SqlConnection(CONNSTRING)    昏暗cmdSelect作为新System.Data.SqlClient.SqlCommand(SELECT u.WindowsUser,u.Email,g.Description,u.Login FROM [ePrimavera]。[DBO]。[PLT_Users]为u [ePrimavera]。[DBO ] [PLT_UserGroups]如UG,[ePrimavera] [DBO] [PLT_Groups]为g,其中u.ID = ug.UserID而ug.GroupID = g.ID和u.WindowsUser像'bancounico \\&放大器; utilizador。文本和放大器;',SQLDATA)
    SQLData.Open()    昏暗dtrReader作为System.Data.SqlClient.SqlDataReader = cmdSelect.ExecuteReader()    如果dtrReader.HasRows然后
        DropDownPerfil.DataValueField =登陆
        DropDownPerfil.DataTextField =说明
        DropDownPerfil.DataSource = dtrReader
        DropDownPerfil.DataBind()
    万一
    SQLData.Close()    返回TRUE
结束功能

的.aspx

 < ASP:DropDownList的ID =DropDownPerfil=服务器
      高度=16px的宽度=202px的CssClass =DropBorderColor>
 < / ASP:DropDownList的>


解决方案

可能的原因是,一些(如果不是全部),您要分配到DropDownList中登录值都出现不止一次。

当你再在DDL中选择一个项目,如果该项目的值出现不止一次,所选择的指数将突出显示第一个实例。为了测试这一点,注释掉 DropDownPerfil.DataValueField =登录

我肯定选择后,它会突出你打算如何选择正确的项目。

Good afternoon people have been trying to fill a dropdown using a sql command, until so good, when I click on the dropdown it shows all the items, but when I try to click on an item in the dropdown it always returns the first item in the dropdown .... follows the codes, what i want to do is get the selected value and item from the dropdown and save it on a label for future use.

I appreciate all the support possible,

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    utilizador.Text = Me.Context.User.Identity.Name
    If (Not Page.IsPostBack) Then
        escolhePerfil()
    End If

    'DropDownPerfil.DataBind()
    lbperfil2.Text = DropDownPerfil.SelectedItem.Text
    lbnome.Text = DropDownPerfil.SelectedValue
End Sub


Function escolhePerfil() As Boolean
    Dim connstring As String = "Data Source=10.2.24.17;Persist Security Info=True;User ID=sa;Password=Pr0dUn1C0$qL;database=ePrimavera"
    Dim SQLData As New System.Data.SqlClient.SqlConnection(connstring)

    Dim cmdSelect As New System.Data.SqlClient.SqlCommand("SELECT  u.WindowsUser,u.Email ,g.Description, u.Login FROM [ePrimavera].[dbo].[PLT_Users] as  u,[ePrimavera].[dbo].[PLT_UserGroups] as ug, [ePrimavera].[dbo].[PLT_Groups] as g where u.ID = ug.UserID And ug.GroupID = g.ID and u.WindowsUser like 'bancounico\" & utilizador.Text & "'", SQLData)
    SQLData.Open()

    Dim dtrReader As System.Data.SqlClient.SqlDataReader = cmdSelect.ExecuteReader()

    If dtrReader.HasRows Then
        DropDownPerfil.DataValueField = "Login"
        DropDownPerfil.DataTextField = "Description"
        DropDownPerfil.DataSource = dtrReader
        DropDownPerfil.DataBind()
    End If
    SQLData.Close()

    Return True
End Function

.aspx

  <asp:DropDownList ID="DropDownPerfil" runat="server" 
      Height="16px" Width="202px" CssClass="DropBorderColor">
 </asp:DropDownList>

解决方案

The likely reason is that some (if not all) the values you are assigning to the DropDownList for Login are occur more than once.

When you then select an item in the DDL, if the value of that item occurs more than once, the selected index will highlight the first instance. To test this, comment out DropDownPerfil.DataValueField = "Login"

I am sure upon selection, it will highlight the correct item you intended on selecting.

这篇关于灌装从SQL错误下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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