현재 작업중인 응용 프로그램은 Service Desk 응용 프로그램입니다. Active Directory에서 오는 직원 이름이 포함 된 DropDownList를 사용하는 양식이 있습니다. 모든 직원이 요청하여 저장할 수 있습니다.ListItem이 더 이상 존재하지 않으면 DropDownList에서 오류가 발생합니다.
직원이 퇴사하여 계정이 Active Directory에서 삭제 될 때 문제가 발생합니다. 다른 직원이 DB를 검색하여 사용 가능한 관련 서비스 티켓을 찾으면이를 열려고 할 때 이름이 DropDownList 항목에 존재하지 않음을 나타내는 오류가 발생합니다.
내가 필요한 기능은 동일한 기능 (Active Directory 항목을 삭제할 수 있음)을 유지하기위한 솔루션이지만 오류는 발생하지 않습니다.
VB에서 ASP.NET에 태그로 표시된대로 사용하고 있습니다. C#을 사용한 솔루션도 환영합니다.
내 문제에 대한 제안에 미리 감사드립니다.
UPDATE : 더 명확하게 할 수 있도록
내가 몇 가지 코드를 추가하고있다.
ASPX :
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"
DataKeyNames="ITRequestId">
<EditItemTemplate>
<br />
<asp:LinkButton ID="LinkButton5" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" CssClass="InsertLink" />
<asp:LinkButton ID="LinkButton6" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" CssClass="CancelLink" />
........
<div id="user" style="float: left;">
<label>User:<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ErrorMessage="User" Display="Dynamic" ControlToValidate="DropDownList5" Text="*" ForeColor="#FF0000"></asp:RequiredFieldValidator></label><br />
<asp:DropDownList ID="DropDownList5" runat="server" SelectedValue='<%# Bind("ITRequestUserName") %>'>
<asp:ListItem Value=""></asp:ListItem>
<asp:ListItem Value="All">All</asp:ListItem>
<asp:ListItem Value="NA">N/A</asp:ListItem>
</asp:DropDownList>
</div>
.........
</EditItemTemplate>
코드 VB BEHIND (이 거대하다, 내가 질문에만 DropDownList로를 걸었습니다) : (이 크다,하지만 오류가 발생하는 pageload 이벤트를 걸었습니다)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not IsPostBack) Then
If Request.UrlReferrer IsNot Nothing Then
ViewState("RefUrl") = Request.UrlReferrer.ToString()
End If
End If
'Handles the mode of the FormView according to the request
If Request.QueryString.Get("ITRequestId") IsNot Nothing Then
FormView1.DefaultMode = FormViewMode.ReadOnly
Dim tName As String = DirectCast(FormView1.Row.FindControl("DropDownList5"), DropDownList).SelectedValue
Dim temptype As String = DirectCast(FormView1.Row.FindControl("DropDownList1"), DropDownList).SelectedItem.Text
Dim myAD As New tActiveDirectory(LDAPpath)
Dim lName As String = HttpContext.Current.User.Identity.Name.ToString()
Dim sDisplayName As String = myAD.GetUserInfo(lName, "displayName")
Dim cName As String = DirectCast(FormView1.Row.FindControl("Label5"), Label).Text
If Not (User.IsInRole("Developers") Or User.IsInRole("Administrators") Or tName = sDisplayName Or cName = sDisplayName) Then
If (temptype = "Access rights") Then
Response.Redirect("../IT/ITAccessDenied.aspx")
End If
End If
If Not (User.IsInRole("Developers") Or User.IsInRole("Administrators") Or cName = sDisplayName) Then
If (temptype = "Account") Then
Response.Redirect("../IT/ITAccessDenied.aspx")
End If
End If
If Not (User.IsInRole("LocalIT")) Then
If (temptype = "Internal IT Task") Then
Response.Redirect("../IT/ITAccessDenied.aspx")
End If
End If
Else
FormView1.DefaultMode = FormViewMode.Insert
Dim tempstatus As DropDownList = DirectCast(FormView1.Row.FindControl("DropDownList2"), DropDownList)
tempstatus.SelectedIndex = 3
End If
End Sub
tName 변수를 선언 할 때 코드의 11 행에서 오류가 발생합니다. 데이터베이스에있는 UserName이 DropDownList에 의해 바인딩되기 때문에 ActiveDirectory에서 삭제되어 목록의 값에 존재하지 않기 때문에 이런 일이 발생합니다. 이것에 어떤 도움을 이해할 수있을 것이다
Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.ItemCreated
Dim d1 As DropDownList
Dim d2 As DropDownList
Dim myAD As New tActiveDirectory(LDAPpath)
Dim users As New ArrayList()
users = myAD.GetAllUsersInfo()
d1 = DirectCast(FormView1.Row.FindControl("DropDownList5"), DropDownList)
d2 = DirectCast(FormView1.Row.FindControl("DropDownList7"), DropDownList)
d1.DataSource = users
d2.DataSource = users
End Sub
Public Function GetAllUsersInfo() As ArrayList
Dim Users As New ArrayList()
Dim myDirectory As New DirectoryEntry(sPath)
Dim mySearcher As New DirectorySearcher(myDirectory)
Dim fullName As String
mySearcher.Filter = "(&(objectCategory=person)(objectClass=user))"
mySearcher.PropertiesToLoad.Add("sn")
mySearcher.PropertiesToLoad.Add("displayName")
mySearcher.Sort.PropertyName = "sn"
mySearcher.Sort.Direction = SortDirection.Ascending
Users.Add("")
Users.Add("N/A")
Users.Add("All")
For Each result As DirectoryServices.SearchResult In mySearcher.FindAll
fullName = result.Properties("displayName")(0).ToString
Users.Add(fullName)
Next
Return Users
End Function
: 여기
는 DropDownList로 채워 코드입니다. 고맙습니다.
를 참조하십시오
–<% # Bind ("ITRequestUserName") %>을 코드 숨김 파일 (예 : Page_Load 또는 DropDownList5_Load)로 이동하여 값을 선택하기 전에 값을 목록에서 확인할 수 있습니다. – Elementenfresser
당신의 제안에 따라 나는 그 문제를 해결할 수있었습니다. 감사! –