This is a migrated thread and some comments may be shown as answers.

Binding RadGrid w/ PowerShell Output

4 Answers 31 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 2
Ron asked on 30 Sep 2013, 03:58 PM
Hello,

I have been working with the RadGrid and binding it to output I receive from PowerShell commands with no issues.  However, when i want to perform operations such as filtering and sorting, I cannot seem to get this to work.  Following is my HTML and my code behind where I am using the NeedDataSource event:

<telerik:RadGrid ID="HealthCheckStatus" runat="server"
    AllowPaging="false"
    AllowFilteringByColumn="true"
    AllowSorting="true"
    ViewStateMode="Enabled">
    <MasterTableView CommandItemDisplay="Top">
        <NoRecordsTemplate>
            <div class="no-records">
                No records to display.
            </div>
        </NoRecordsTemplate>
        <Columns>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Database Name" />
            <telerik:GridBoundColumn DataField="Status" HeaderText="Status" />
            <telerik:GridBoundColumn DataField="CopyQueueLength" HeaderText="Copy Queue Length" />
            <telerik:GridBoundColumn DataField="ReplayQueueLength" HeaderText="Replay Queue Length" />
            <telerik:GridDateTimeColumn DataField="LastInspectionLogTime" HeaderText="Last Inspection Log Time" />
            <telerik:GridBoundColumn DataField="ContentIndexState" HeaderText="Content Index State" />
        </Columns>
        <CommandItemSettings
            ShowAddNewRecordButton="false"
            ShowExportToExcelButton="true"
            ShowExportToCsvButton="true"
            ShowRefreshButton="false"
            />
    </MasterTableView>
    <ExportSettings Excel-Format="ExcelML"
        HideStructureColumns="true"
        ExportOnlyData="true"
        IgnorePaging="true"
        OpenInNewWindow="true"
        />
</telerik:RadGrid>



Protected Sub HealthCheckStatus_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles HealthCheckStatus.NeedDataSource
 
    Dim queues As Collection(Of PSObject) = PSExchange( _
            "get-mailboxdatabasecopystatus * | sort CopyQueueLength -descending | sort Name")
    HealthCheckStatus.DataSource = queues
 
End Sub

As a note, I have tried modifying the PoweShell command to not have a default sort order and just utilize the primary cmdlet of get-mailboxdatabasecopystatus * and still cannot get it to work.  All that I get back is the same table unsorted and unfiltered every time.

Any help in understanding how I can get this to work would be greatly appreciated!

Thanks,
Ron

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 03 Oct 2013, 12:18 PM
Hi Ron,

Could you please try to bind the ASP.NET GridView control to the same data? I feel that the problem might be related to the returned data and not to the control itself.
Thanks in advance for your cooperation.

Regards,
Daniel
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Ron
Top achievements
Rank 2
answered on 03 Oct 2013, 01:02 PM
I am not sure how that will help as the sorting and filtering is not the same between the controls where the ASP.NET controld requires a lot more custom code to perform when databinding in code behind.  Is there something specific you are looking to see?

In any case, I did try binding the data to the ASP.NET control and like the Telerik control, I get the same data returned in the grid.  However, it is not getting the data back to the grid that is the problem, it is the sorting and filtering of the data.  When I try to sort the data on the RadGrid, the data is returned to the grid but in the initial state, it never sorts and never filters.
0
Ron
Top achievements
Rank 2
answered on 03 Oct 2013, 01:21 PM
Well I now have it working, but in order to do that... I needed to modify the NeedDataSource event code to the following:

Protected Sub HealthCheckStatus_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles HealthCheckStatus.NeedDataSource
 
    Dim queues As Collection(Of PSObject) = PSExchange("get-mailboxdatabasecopystatus * | sort Name")
 
    Dim dt As DataTable = New DataTable("Status")
    dt.Columns.Add("Name")
    dt.Columns.Add("Status")
    dt.Columns.Add("CopyQueueLength")
    dt.Columns.Add("ReplayQueueLength")
    dt.Columns.Add("ContentIndexState")
 
    For Each prop As PSObject In queues
        Dim dr As DataRow = dt.NewRow
        dr("Name") = prop.Properties("Name").Value.ToString
        dr("Status") = prop.Properties("Status").Value.ToString
        dr("CopyQueueLength") = prop.Properties("CopyQueueLength").Value.ToString
        dr("ReplayQueueLength") = prop.Properties("ReplayQueueLength").Value.ToString
        dr("ContentIndexState") = prop.Properties("ContentIndexState").Value.ToString
        dt.Rows.Add(dr)
    Next
 
    HealthCheckStatus.DataSource = dt
 
End Sub

For some reason, the RadGrid does not like to bind directly to a Collection(Of PSObject) type and allow filtering/sorting on it without first putting the data into a datatable and then binding the grid to the datatable.  Can I get some confirmation if you are able to replicate this behaviour as well?
0
Accepted
Daniel
Telerik team
answered on 08 Oct 2013, 11:41 AM
Hello Ronald,

I made a simple runnable demo on my end and after examining the PSObjects I conclude that they can't be bound directly to the control. A possible solution would be to use some kind of wrapper like DataTable. I think it is also possible to write your own custom type descriptor to handle these objects but I'm afraid this is out of the scope of our components.

Regards,
Daniel
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Ron
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Ron
Top achievements
Rank 2
Share this question
or