【问题标题】:How do I populate multiple textboxes based on value of another textbox or dropdownlist?如何根据另一个文本框或下拉列表的值填充多个文本框?
【发布时间】:2013-02-12 16:38:02
【问题描述】:

你好。

我们有一个网络表单,员工可以使用它来请求诸如从远程位置通过 VPN 访问公司资源之类的事情。

我正在从 Active Directory 填充一个下拉列表框。这很好用。

然后我有一个文本框,它也通过简单地分配登录用户的值从 Active Directory 填充,如下所示:

textbox1.Text = User.Identity.Name

基于分配给 textbox1.Text 的我的名字的值

其余的 texboxes 使用以下代码填充了我的工作信息:

    textbox1.Text = User.Identity.Name
    textbox1.Text = StrConv(textbox1.Text, vbProperCase)

    txtdate.Text = DateTime.Now.ToString("MM/dd/yyyy")
    Try
        'Creates a Directory Entry Instance with the Username and Password provided
        Dim deSystem As New DirectoryEntry("LDAP://OU=Departments,DC=domaname, DC=com", "usrname", "password")

        'Authenticacion type Secure
        deSystem.AuthenticationType = AuthenticationTypes.Secure

        'Creates a Directory Searcher Instance
        Dim dsSystem As New DirectorySearcher(deSystem)

        'sAMAccountName is equal to our username passed in.            
        dsSystem.Filter = "sAMAccountName=" & textbox1.Text

        'Properties that the Procedures will load from Active Directory
        dsSystem.PropertiesToLoad.Add("mail") 'email address
        dsSystem.PropertiesToLoad.Add("department") 'dept
        dsSystem.PropertiesToLoad.Add("physicalDeliveryOfficeName") 'office
        dsSystem.PropertiesToLoad.Add("title") 'title, eg programmer1
        dsSystem.PropertiesToLoad.Add("telephoneNumber") 'phone
        dsSystem.PropertiesToLoad.Add("streetAddress") 'street address
        dsSystem.PropertiesToLoad.Add("l") 'city
        dsSystem.PropertiesToLoad.Add("st") 'state
        dsSystem.PropertiesToLoad.Add("postalCode") 'zip code
        dsSystem.PropertiesToLoad.Add("EmployeeId") 'empid 
        dsSystem.PropertiesToLoad.Add("givenName") '//first name from active directory
        dsSystem.PropertiesToLoad.Add("sn") '//lastname from active directory
        'Find the user data
        Dim srSystem As SearchResult = dsSystem.FindOne()

        'Obtains the properties recently loaded
        txtemail.Text = srSystem.Properties("mail").Item(0).ToString
        dept.Text = srSystem.Properties("department").Item(0).ToString
        office.Text = srSystem.Properties("physicalDeliveryOfficeName").Item(0).ToString
        txttitle.Text = srSystem.Properties("title").Item(0).ToString
        phone.Text = srSystem.Properties("telephoneNumber").Item(0).ToString
        workaddress.Text = srSystem.Properties("streetAddress").Item(0).ToString
        city.Text = srSystem.Properties("l").Item(0).ToString
        state.Text = srSystem.Properties("st").Item(0).ToString
        zipcode.Text = srSystem.Properties("postalCode").Item(0).ToString
        hiddenempId.Value = srSystem.Properties("EmployeeId").Item(0).ToString
        HiddenFName.Value = srSystem.Properties("givenName").Item(0).ToString
        HiddenLName.Value = srSystem.Properties("sn").Item(0).ToString

这也很好用。

这就是我的问题所在。

最初,当用户登录时,根据从 Active Directory 记录的用户名,其余文本框将填充用户的信息。抱歉在这里重复我自己。

但是,有时登录的用户不一定是需要reguest的用户。

换句话说,我可以登录以填写其他员工的请求。

在这种情况下,我需要从 Active Directory 填充的下拉列表中选择我正在完成请求的用户的名称。

当我从下拉列表中选择此名称时,它会替换我自己在 textbox1.Text 上的名称。

这很好,但其余的文本框保留了我自己的信息。

我需要做些什么来确保替换我在 textbox1.Text 上的原始名称的名称也替换了其余文本框中的信息?

我会按要求发布更多信息。

在此先感谢

【问题讨论】:

    标签: asp.net vb.net active-directory


    【解决方案1】:

    不是在表单加载时加载所有文本框,而是从用户名文本框的TextChanged 事件加载它们。这样,每当用户名文本框发生更改时,所有其他文本框都会自动重新加载以反映更改。

    【讨论】:

    • 它工作得几乎完美。唯一的问题是我们希望登录用户的名称默认加载文本框。现在,除了用户第一次登录时,所有的文本框都是空白的。我是否仍然默认加载所有内容?
    • 如果您在表单加载时设置用户名文本框,则应该立即触发TextChanged 事件以填充其余字段。
    猜你喜欢
    • 2021-12-04
    • 1970-01-01
    • 2019-09-17
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 2012-10-31
    • 1970-01-01
    相关资源
    最近更新 更多