本文介绍了如何将sortedlist绑定到ListView控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找到了此代码,并一直试图将其绑定到listview控件,但没有成功(其想法是在另一个面板中显示在gridview中定义的组的成员).如果我设置了ObjectDatasource并使用DefaultValue,它将显示该组的成员(尽管格式已不符合要求).
背后的代码
I found this code and have been attempting to Bind it to a listview control with no success (The idea is to display the members of a group defined in a gridview in another Panel). If I setup an ObjectDatasource and use a DefaultValue it displays the members of that group (although the formating is out of whack).
Code behind
public SortedList FillMembersList(string groupName)
{
SortedList groupMembers = new SortedList();
string sam = "";
string fname = "";
string lname = "";
string active = "";
DirectoryEntry de = new DirectoryEntry("LDAP://DC=CSUMAIN,DC=csu,DC=edu,DC=au");
DirectorySearcher ds = new DirectorySearcher(de, "(objectClass=person)");
ds.Filter = "(memberOf=CN=" + groupName + ",OU=Distribution Groups (DLs),OU=Managed,DC=CSUMAIN,DC=csu,DC=edu,DC=au)";
ds.PropertiesToLoad.Add("givenname");
ds.PropertiesToLoad.Add("samaccountname");
ds.PropertiesToLoad.Add("sn");
ds.PropertiesToLoad.Add("useraccountcontrol");
foreach (SearchResult sr in ds.FindAll())
{
try
{
sam = sr.Properties["samaccountname"][0].ToString();
fname = sr.Properties["givenname"][0].ToString();
lname = sr.Properties["sn"][0].ToString();
active = sr.Properties["useraccountcontrol"][0].ToString();
}
catch
{
}
// don''t grab disabled users
if (active.ToString() != "514")
{
groupMembers.Add(sam.ToString(), (fname.ToString() + " " + lname.ToString()));
}
}
return groupMembers;
}
前面的代码
Code in front
<br />
<pre lang="xml"><asp:Panel Style="display: none; left: 630px; z-index: 100; position: absolute;<br />
top: 52px" ID="PanelEditGroups" runat="server" Height="267px"<br />
Width="258px" BorderWidth="2px"<br />
BorderStyle="Inset" ScrollBars="Vertical" EnableViewState="True"<br />
Visible="True"><br />
<br />
<asp:ListView ID="ADGroupListView" runat="server"><br />
<LayoutTemplate><br />
<table cellpadding="2" width="640px" border="1" runat="server" id="table"><br />
<tr id="Tr1" runat="server"><br />
<th id="Th1" runat="server">test</th><br />
</tr><br />
<tr runat="server" id="itemPlaceholder" /><br />
</table><br />
</LayoutTemplate><br />
<itemtemplate><%# Eval("Key")%></itemtemplate><br />
<br />
</asp:ListView><br />
<br />
</asp:Panel></pre><br />
<br />
推荐答案
这篇关于如何将sortedlist绑定到ListView控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!