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

RadGrid with Client Row Selecting

4 Answers 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 1
Benjamin asked on 22 May 2014, 04:43 PM
Hi all,

I am working with a RadGrid with a NestedView that has Client row-selecting enabled and has EnablePostBackOnRowClick set to True.  When I attempt to expand a row (either by the Client "RowClick" or by using the expand column), I am handling the ItemCommand event server side to attempt to close any currently expanded rows, and expand only the currently clicked row (like in the "Overview" demo for the RadGrid).  Here is the RadGrid:

<telerik:RadGrid ID="gridShipmentsToBill" runat="server" Width="100%" DataSourceID="ShipmentsToBill" AllowSorting="True" AutoGenerateColumns="False" GridLines="Vertical">
                <ClientSettings EnablePostBackOnRowClick="true" EnableRowHoverStyle="True">
                    <Scrolling AllowScroll="True" ScrollHeight="500px" UseStaticHeaders="true"></Scrolling>
                    <Selecting AllowRowSelect="true" />
                </ClientSettings>
                 
                <MasterTableView HierarchyLoadMode="ServerBind" DataKeyNames="Shipment_Key" DataSourceID="ShipmentsToBill" RetainExpandStateOnRebind="false">
                    <Columns>
                        <telerik:GridBoundColumn DataField="Shipment_Key" ReadOnly="True" HeaderText="CPU #" SortExpression="Shipment_Key" UniqueName="Shipment_Key">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Shipment_AWorBOL" HeaderText="AWB/BOL #" SortExpression="Shipment_AWorBOL" UniqueName="Shipment_AWorBOL">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Customer_Name" HeaderText="Customer" SortExpression="Customer_Name" UniqueName="Customer_Name">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Shipment_Description" HeaderText="Description" SortExpression="Shipment_Description" UniqueName="Shipment_Description">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Voyage_ArriveDate" HeaderText="Arrival Date" SortExpression="Voyage_ArriveDate" DataFormatString="{0:MM/dd/yyyy}" UniqueName="Voyage_ArriveDate" DataType="System.DateTime">
                        </telerik:GridBoundColumn>
                    </Columns>
                    <NestedViewSettings DataSourceID="GeneralShipmentData">
                        <ParentTableRelation>
                            <telerik:GridRelationFields MasterKeyField="Shipment_Key" DetailKeyField="Shipment_Key"></telerik:GridRelationFields>
                        </ParentTableRelation>
                    </NestedViewSettings>
                    <NestedViewTemplate>
                        <div class="generalInfoForm">
                            <div class="leftForm">
                                <span>
                                    <label>Customer:</label>
                                    <%# Eval("Customer_Num")%> <%# Eval("Customer_Name") %></span>
                                <span>
                                    <label>Consignee:</label>
                                    <%# Eval("Consignee_Num")%> <%# Eval("Consignee_Name") %></span>
                                <span>
                                    <label>Arrival Date:</label>
                                    <%# Eval("Voyage_ArriveDate", "{0:MM/dd/yyyy}")%></span>
                            </div>
 
                            <div class="rightForm">
                                <span>
                                    <label>AWB/BOL:</label>
                                    <%# Eval("Shipment_AWorBOL")%></span>
                                <span>
                                    <label>Carrier:</label>
                                    <%# Eval("Carrier_Name")%></span>
                                <span>
                                    <label>Vessel:</label>
                                    <%# Eval("Vessel_Name") %></span>
                                <span>
                                    <label>Forwarding Agent:</label>
                                    <%# Eval("ForwardingAgent_Name") %></span>
                            </div>
 
                            <div class="middleForm"><%# Eval("Shipment_Description")%></div>
 
                            <div class="leftForm">
                                <span>
                                    <label>Volume Weight:</label>
                                    <%# Eval("ShipPackage_VolumeWeight")%></span>
                                <span>
                                    <label>Weight:</label>
                                    <%# Eval("ShipPackage_TotalWeight")%></span>
                                <span>
                                    <label>Cube:</label>
                                    <%# Eval("ShipPackage_TotalVolume")%></span>
                                <span>
                                    <label>Freight:</label>
                                    <%# Eval("ShipmentCover_FaceFreight")%></span>
                            </div>
                        </div>
                    </NestedViewTemplate>
                </MasterTableView>
            </telerik:RadGrid>
And here is the ItemCommand event handler:

Protected Sub gridShipmentsToBill_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles gridShipmentsToBill.ItemCommand
        If e.CommandName = "RowClick" OrElse e.CommandName = RadGrid.ExpandCollapseCommandName Then
            Dim previousState As Boolean = e.Item.Expanded
 
            If e.CommandName = "ExpandCollapse" Then
                previousState = Not previousState
            End If
 
            CollapseAllRows()
            e.Item.Expanded = Not previousState
        End If
    End Sub
 
    Private Sub CollapseAllRows()
        For Each item As GridItem In gridShipmentsToBill.MasterTableView.Items
            item.Expanded = False
        Next
    End Sub

If I was to only click on the expand/collapse column to open the rows, I would have no issue and the Grid would behave as I expect.  But if I click on a row (which should expand that Row's NestedView), I see that the following uncaught exception is displayed in my browser's console:

"Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: DataBinding: 'ToString()' is not a valid indexed expression."

If, however, I change AllowRowSelect to be set to False (while leaving EnablePostbackOnRowClick set to True), the program works as I would expect (when clicking the expand/collapse column or clicking the row).

While I could probably work with this, I'm wondering why it is not working when AllowRowSelect is set to True.  (Also, the default styling for the SelectedRow is not applied when AllowRowSelect is set to False).

I'm fairly new to Telerik's controls, so I may be missing something obvious, but thanks for any help/suggestions.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 May 2014, 06:30 AM
Hi Benjamin,

I have tried your code and it works fine at my end. The issue is not related with this code, please provide your complete code behind snippet. Check the below sample code, which works fine at my end.

ASPX:
<telerik:RadGrid ID="gridShipmentsToBill" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False">
    <ClientSettings EnablePostBackOnRowClick="true" EnableRowHoverStyle="True">
        <Selecting AllowRowSelect="true" />
    </ClientSettings>
    <MasterTableView HierarchyLoadMode="ServerBind" DataKeyNames="OrderID">
        <Columns>
            <telerik:GridBoundColumn DataField="OrderID" ReadOnly="True" HeaderText="OrderID" SortExpression="OrderID" UniqueName="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" SortExpression="ShipCity" UniqueName="ShipCity">
            </telerik:GridBoundColumn>
        </Columns>
        <NestedViewSettings DataSourceID="SqlDataSource1">
            <ParentTableRelation>
                <telerik:GridRelationFields MasterKeyField="OrderID" DetailKeyField="OrderID"></telerik:GridRelationFields>
            </ParentTableRelation>
        </NestedViewSettings>
        <NestedViewTemplate>
            <div>
                Customer:
                <%# Eval("OrderID")%>
                ShipCity:
                <%# Eval("ShipCity")%>
                Order Date:
                <%# Eval("OrderDate", "{0:MM/dd/yyyy}")%>
            </div>
        </NestedViewTemplate>
    </MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"  SelectCommand="SELECT  * FROM [Orders]"></asp:SqlDataSource>

VB:
Protected Sub gridShipmentsToBill_ItemCommand1(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles gridShipmentsToBill.ItemCommand
       If e.CommandName = "RowClick" OrElse e.CommandName = RadGrid.ExpandCollapseCommandName Then
           Dim previousState As Boolean = e.Item.Expanded
 
           If e.CommandName = "ExpandCollapse" Then
               previousState = Not previousState
           End If
           CollapseAllRows()
           e.Item.Expanded = Not previousState
       End If
   End Sub
   Private Sub CollapseAllRows()
       For Each item As GridItem In gridShipmentsToBill.MasterTableView.Items
           item.Expanded = False
       Next
   End Sub

Thanks,
Princy
0
Benjamin
Top achievements
Rank 1
answered on 23 May 2014, 05:23 PM
Sure, here is the rest of the code-behind file.

Option Strict On
Imports System.Data.Odbc
Imports System.Web.Configuration
Imports System.Data
Imports Telerik.Web.UI
 
Partial Class Start
    Inherits System.Web.UI.Page
 
    ' GAACSDataAccessor to work with the data in the GAACS DB
    Private GAACSData As GAACSDataAccessor
    ' billingCalculator to estimate charges for a particular Shipment
    Private BillingCalculator As BillingChargesEstimator
 
    Private totalShipmentsCount As Integer
 
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            Me.gridShipmentsToBill.DataBind()
            Me.gridShipmentsToBill.MasterTableView.Caption = totalShipmentsCount & " Shipments Need Billing"
        End If
    End Sub
 
    Protected Sub btnRetrieveGAACSData_Click(sender As Object, e As EventArgs) Handles btnRetrieveGAACSData.Click
        RetrieveDataFromGaacs()
    End Sub
 
    ' Allow the GAACSData object to retrieve data from GAACS
    Private Sub RetrieveDataFromGaacs()
        GAACSData = New GAACSDataAccessor(-5)
        Try
            GAACSData.RetrieveData()
        Catch e As Exception                      
            lblNumberOfShipments.Text = e.Message
        End Try
 
        gridShipmentsToBill.DataBind()
        Me.gridShipmentsToBill.MasterTableView.Caption = totalShipmentsCount & " Shipments Need Billing"
    End Sub
 
 
    Protected Sub gridShipmentsToBill_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles gridShipmentsToBill.ItemCommand
        If e.CommandName = "RowClick" OrElse e.CommandName = RadGrid.ExpandCollapseCommandName Then
            Dim previousState As Boolean = e.Item.Expanded
 
            If e.CommandName = "ExpandCollapse" Then
                previousState = Not previousState
            End If
 
            CollapseAllRows()
            e.Item.Expanded = Not previousState
        End If
    End Sub
 
    Private Sub CollapseAllRows()
        For Each item As GridItem In gridShipmentsToBill.MasterTableView.Items
            item.Expanded = False
        Next
    End Sub
 
    Protected Sub gridShipmentsToBill_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles gridShipmentsToBill.ItemDataBound
        If TypeOf e.Item Is GridPagerItem Then
            totalShipmentsCount = CType(e.Item, GridPagerItem).Paging.DataSourceCount
        End If
    End Sub
End Class
 
If posting the rest of the .aspx file would help I can do that as well.

Thanks,
Ben
0
Benjamin
Top achievements
Rank 1
answered on 23 May 2014, 05:56 PM
Oh and I think I see another difference. I am using two different DataSources - one for the MasterTableView and one for the NestedViewSettings.
0
Benjamin
Top achievements
Rank 1
answered on 23 May 2014, 07:23 PM
Hi Princy,

It appears the problem was with my Control Parameter in my GeneralShipmentData DataSource.  I had the PropertyName set to SelectedValue.ToString(), and after I took away the "ToString()" it works fine.  
Thanks for your quick response to my problem,
Ben
Tags
Grid
Asked by
Benjamin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Benjamin
Top achievements
Rank 1
Share this question
or