首页 文章

如何向RadExplorer添加自定义列

提问于
浏览
0

如何向RadExplorer添加自定义列我向RadExplorer添加了两列日期和所有者 . 演示网址 .

http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/applicationscenarios/customgridcolumns/defaultcs.aspx

以前我在获取两个coloumn Headers 时获取FileName和大小

private void AddGridColumn(string name, string uniqueName, bool sortable)
          {
         RemoveGridColumn(uniqueName);
         // Add a new column with the specified name
         GridTemplateColumn gridTemplateColumn1 = new GridTemplateColumn();
         gridTemplateColumn1.HeaderText = name;
         if (sortable)
        gridTemplateColumn1.SortExpression = uniqueName;
        gridTemplateColumn1.UniqueName = uniqueName;
        gridTemplateColumn1.DataField = uniqueName;
        Aspx_RadFileExplorer.Grid.Columns.Add(gridTemplateColumn1);
         }
Function For ResolveRootDirectoryAsTree 
    <pre>
     public override DirectoryItem ResolveRootDirectoryAsTree ( string xszPath )
     {
    PathPermissions zPathPermission = FullPermissions;
    if ( xszPath.Equals ( "Document/Private" ) )
    zPathPermission = PathPermissions.Read;
    else if ( xszPath.Equals ( "Document/Public" ) )
    zPathPermission = PathPermissions.Read | PathPermissions.Upload;
         return new DirectoryItem(GetName(xszPath), GetDirectoryPath(xszPath), xszPath, GetDate(xszPath), zPathPermission, GetChildFiles(xszPath), GetChildDirectories(xszPath));
   }
</pre>

ResolveDirectory的功能

public override DirectoryItem ResolveDirectory(string xszPath )
    {
    PathPermissions zPathPermission = FullPermissions;
    if ( xszPath.Equals ( "Document/Private" ) )
    zPathPermission = PathPermissions.Read;
    else if ( xszPath.Equals ( "Document/Public" ) )
    zPathPermission = PathPermissions.Read | PathPermissions.Upload; 

 DirectoryItem[] zdlDirectories = GetChildDirectories ( xszPath );
                   return new DirectoryItem ( GetName ( xszPath ), EndWithSlash ( GetDirectoryPath ( xszPath ) ), string.Empty, string.Empty, zPathPermission, GetChildFiles ( xszPath ), zdlDirectories );
}
private string GetName ( string xszPath )
{
if ( xszPath == null )
{
    return string.Empty;
}
 return xszPath.Substring ( xszPath.LastIndexOf ( '/' ) + 1 );
}

在此函数中,我将获取OwnerID和Date作为字符串LoadDocuments() . 如何将所有者ID显示为所有者自定义字段和日期到日期字段

private void SafeLoadDocument ( string xszUserID )
        {
        try
        {
         DataTable zdtReturn = new DataTable();
        if ( ViewState["m_DocumentTable"] == null )
        ViewState["m_DocumentTable"] = EMSBLCRM.LoadDocuments( xszUserID );
         zdtReturn = (DataTable)ViewState["m_DocumentTable"];
         foreach (DataRow dr in zdtReturn.Rows)
         {
             double zdbFileSize = Convert.ToDouble(dr["fld_document_latest_attachment_size"]);
        string zsztest = String.Format("{0:#,##0}", zdbFileSize);
         dr["fld_document_latest_attachment_size"] = zsztest;
                             Convert.ToDouble(dr["fld_document_created_on"]);
        string date = dr["fld_document_created_on"].ToString();
        string date2 = date.Substring(0, 10);
        }
        Session["sesDocumentTable"] = ViewState["m_DocumentTable"];
        }
        catch ( Exception e )
        {
            Utilities.SendCrashEMail ( ref e );
        }
        }

1 回答

  • 0

    这是文档的a link,以下是代码 .

    // Add a new 'custom column for the file owner'
    GridTemplateColumn gridTemplateColumn2 = new GridTemplateColumn();
    gridTemplateColumn2.HeaderText = "Owner Name";
    gridTemplateColumn2.SortExpression = "Owner";
    gridTemplateColumn2.UniqueName = "Owner";
    gridTemplateColumn2.DataField = "Owner";
    RadFileExplorer1.Grid.Columns.Add(gridTemplateColumn2);// Add the second column
    
    //And the code for adding value for the file entry for the custom column.
    public override DirectoryItem ResolveDirectory(string path)
    {
        // Update all file items with the additional information (date, owner)
        DirectoryItem oldItem = base.ResolveDirectory(path);
        foreach (FileItem fileItem in oldItem.Files)
        {
            // Get the information from the physical file
            FileInfo fInfo = new FileInfo(Context.Server.MapPath(VirtualPathUtility.AppendTrailingSlash(oldItem.Path) + fileItem.Name));
            // Add the information to the attributes collection of the item. It will be automatically picked up by the FileExplorer
            // If the name attribute matches the unique name of a grid column
            fileItem.Attributes.Add("Date", fInfo.CreationTime.ToString());
            // Type targetType = typeof(System.Security.Principal.NTAccount);
            // string value = fInfo.GetAccessControl().GetOwner(targetType).Value.Replace("\\", "\\\\");
            string ownerName = "Telerik";
            fileItem.Attributes.Add("Owner", ownerName);
        }
        return oldItem;
    }
    

    希望这对你有所帮助 .

相关问题