我几天来一直在研究这个问题,并在这里和其他网站上尝试了很多建议,但没有任何运气。我有一个基于asp.net的gridview的C#代码隐藏,我想从类中提取一个名单列表并在下拉列表中显示它们。这是我到目前为止的代码。
===================================首先,Dropdownlist的类:
public DataTable GetList()
{
// Set method to execute
_smartObject.MethodToExecute = "GetList";
// Assign Input properties
if (Title != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Title"], Title);
}
if (LastName != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["LastName"], LastName);
}
if (FirstName != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["FirstName"], FirstName);
}
if (EmailAddress != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["EmailAddress"], EmailAddress);
}
if (Company != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Company"], Company);
}
if (alias != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["alias"], alias);
}
if (Phone != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Phone"], Phone);
}
if (JobTitle != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["JobTitle"], JobTitle);
}
if (Manager != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Manager"], Manager);
}
if (ID != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["ID"], ID);
}
if (ContentType != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["ContentType"], ContentType);
}
if (Modified != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Modified"], Modified);
}
if (Created != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Created"], Created);
}
if (Author != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Author"], Author);
}
if (Editor != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Editor"], Editor);
}
if (FileLeafRef != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["FileLeafRef"], FileLeafRef);
}
if (ItemChildCount != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["ItemChildCount"], ItemChildCount);
}
if (FolderChildCount != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["FolderChildCount"], FolderChildCount);
}
try
{
SmartObjectClientServer soServer = CreateConnection();
// Execute SmartObject
using (soServer.Connection)
{
return soServer.ExecuteListDataTable(_smartObject);
}
}
catch (Exception ex)
{
throw DisplayError(ex);
}
finally
{
ClearProperties();
}
}
public DbDataReader GetList_Reader()
{
// Set method to execute
_smartObject.MethodToExecute = "GetList";
// Assign Input properties
if (Title != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Title"], Title);
}
if (LastName != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["LastName"], LastName);
}
if (FirstName != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["FirstName"], FirstName);
}
if (EmailAddress != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["EmailAddress"], EmailAddress);
}
if (Company != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Company"], Company);
}
if (alias != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["alias"], alias);
}
if (Phone != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Phone"], Phone);
}
if (JobTitle != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["JobTitle"], JobTitle);
}
if (Manager != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Manager"], Manager);
}
if (ID != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["ID"], ID);
}
if (ContentType != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["ContentType"], ContentType);
}
if (Modified != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Modified"], Modified);
}
if (Created != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Created"], Created);
}
if (Author != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Author"], Author);
}
if (Editor != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["Editor"], Editor);
}
if (FileLeafRef != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["FileLeafRef"], FileLeafRef);
}
if (ItemChildCount != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["ItemChildCount"], ItemChildCount);
}
if (FolderChildCount != null)
{
SetPropertyValue(_smartObject.ListMethods["GetList"].InputProperties["FolderChildCount"], FolderChildCount);
}
try
{
SmartObjectClientServer soServer = CreateConnection();
// Execute SmartObject
using (soServer.Connection)
{
return soServer.ExecuteListReader(_smartObject);
}
}
catch (Exception ex)
{
throw DisplayError(ex);
}
finally
{
ClearProperties();
}
}
public DataTable GetListDynamic(string SharePointURL)
{
// Verify required properties
if (SharePointURL == null)
{
throw new NullReferenceException("Value required for property [SharePointURL]");
}
// Set method to execute
_smartObject.MethodToExecute = "GetListDynamic";
// Assign Input properties
if (SharePointURL != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["SharePointURL"], SharePointURL);
}
if (Title != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Title"], Title);
}
if (LastName != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["LastName"], LastName);
}
if (FirstName != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["FirstName"], FirstName);
}
if (EmailAddress != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["EmailAddress"], EmailAddress);
}
if (Company != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Company"], Company);
}
if (alias != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["alias"], alias);
}
if (Phone != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Phone"], Phone);
}
if (JobTitle != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["JobTitle"], JobTitle);
}
if (Manager != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Manager"], Manager);
}
if (ID != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["ID"], ID);
}
if (ContentType != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["ContentType"], ContentType);
}
if (Modified != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Modified"], Modified);
}
if (Created != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Created"], Created);
}
if (Author != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Author"], Author);
}
if (Editor != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Editor"], Editor);
}
if (FileLeafRef != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["FileLeafRef"], FileLeafRef);
}
if (ItemChildCount != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["ItemChildCount"], ItemChildCount);
}
if (FolderChildCount != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["FolderChildCount"], FolderChildCount);
}
try
{
SmartObjectClientServer soServer = CreateConnection();
// Execute SmartObject
using (soServer.Connection)
{
return soServer.ExecuteListDataTable(_smartObject);
}
}
catch (Exception ex)
{
throw DisplayError(ex);
}
finally
{
ClearProperties();
}
}
public DbDataReader GetListDynamic_Reader(string SharePointURL)
{
// Verify required properties
if (SharePointURL == null)
{
throw new NullReferenceException("Value required for property [SharePointURL]");
}
// Set method to execute
_smartObject.MethodToExecute = "GetListDynamic";
// Assign Input properties
if (SharePointURL != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["SharePointURL"], SharePointURL);
}
if (Title != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Title"], Title);
}
if (LastName != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["LastName"], LastName);
}
if (FirstName != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["FirstName"], FirstName);
}
if (EmailAddress != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["EmailAddress"], EmailAddress);
}
if (Company != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Company"], Company);
}
if (alias != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["alias"], alias);
}
if (Phone != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Phone"], Phone);
}
if (JobTitle != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["JobTitle"], JobTitle);
}
if (Manager != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Manager"], Manager);
}
if (ID != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["ID"], ID);
}
if (ContentType != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["ContentType"], ContentType);
}
if (Modified != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Modified"], Modified);
}
if (Created != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Created"], Created);
}
if (Author != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Author"], Author);
}
if (Editor != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["Editor"], Editor);
}
if (FileLeafRef != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["FileLeafRef"], FileLeafRef);
}
if (ItemChildCount != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["ItemChildCount"], ItemChildCount);
}
if (FolderChildCount != null)
{
SetPropertyValue(_smartObject.ListMethods["GetListDynamic"].InputProperties["FolderChildCount"], FolderChildCount);
}
try
{
SmartObjectClientServer soServer = CreateConnection();
// Execute SmartObject
using (soServer.Connection)
{
return soServer.ExecuteListReader(_smartObject);
}
}
catch (Exception ex)
{
throw DisplayError(ex);
}
finally
{
ClearProperties();
}
}
#endregion Methods
internal DataTable GetListDynamic()
{
throw new NotImplementedException();
}
}
public class MYWORKFLOW_AllUsers_properties
{
#region Fields (22)
private string _SharePointSiteURL;
private string _Title;
private string _LastName;
private string _FirstName;
private string _EmailAddress;
private string _Company;
private string _alias;
private string _Phone;
private string _JobTitle;
private string _Manager;
private int? _ID;
private string _ContentType;
private DateTime? _Modified;
private DateTime? _Created;
private string _Author;
private string _Editor;
private string _FileLeafRef;
private string _ItemChildCount;
private string _FolderChildCount;
private FileObject _Attachment_K2_ServiceDefined;
private HyperLinkObject _LinkToItem_K2_ServiceDefined;
private string _Folder_K2_ServiceDefined;
#endregion Fields
#region Constructors (1)
protected MYWORKFLOW_AllUsers_properties()
{
}
#endregion Constructors
}
#region Object Classes
#endregion
}
=============== ASPX =============================== =======================
==========================================代码背后=== ================
public void ddlusers(object sender, EventArgs e)
{
MYWORKFLOW_AllUsers allusers = new MYWORKFLOW_AllUsers();
DataTable dt = allusers.GetList();
ddlAllUsers.DataSource = dt;
ddlAllUsers.DataTextField = "userName";
ddlAllUsers.DataValueField = "EmailAddress";
ddlAllUsers.DataBind();
}
private object MYWORKFLOW_AllUsers()
{
throw new NotImplementedException();
}
非常感谢任何建议。非常感谢你!