Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
675
Trying to combine Row Selection and Sorting behaviors on WebHierarchicalDataGrid
posted

I'm having trouble coding a WHDG for both Sorting and Row Selection behaviors on post-back.

I have several behaviors and events configured including Row Selection Changed.

    <cc1:QueryResults ID="QueryResults1" runat="server"

         AutoGenerateBands="False" AutoGenerateColumns="False"

         oninitializerow="QueryResults1_InitializeRow"

         EnableAjax="False"

         oncalculatecustomsummary="QueryResults1_CalculateCustomSummary"

         Height="450px" DefaultColumnWidth="100px" Width="100%"

         onrowselectionchanged="QueryResults1_RowSelectChanged"

         onload="QueryResults1_Load" >

         <ClientEvents Initialize="queryEventInitGrid"/>

         <GroupingSettings EnableColumnGrouping="True" InitialRowExpandState="Collapsed"

                     ShowBandInGroupByArea="False">         </GroupingSettings>

         <Behaviors>

             <ig:SummaryRow Enabled="False" EnableInheritance="True"></ig:SummaryRow>

             <ig:ColumnMoving></ig:ColumnMoving>

             <ig:Selection CellClickAction="Row" RowSelectType="Multiple"

                 CellSelectType="Multiple" EnableCrossPageSelection="True">

             </ig:Selection>

             <ig:Paging PagerCssClass="leftPaging"></ig:Paging>

             <ig:ColumnResizing></ig:ColumnResizing>

             <ig:Sorting SortingMode="Multi"></ig:Sorting>

         </Behaviors>

     </cc1:QueryResults>

 

I have EnableViewState = true and EnableDataViewState = false and am setting the database on Post-back in Load event of grid.

if (IsPostBack && QueryResultsData != null)

{

    DataTable dt = (DataTable)QueryResultsData;

    QueryResults1.DataSource = dt.DataSet;

    this.DataBind();

}

I have another button which fires an event to be handled on the server, where I need to determine which rows are selected.

I find that the RowSelectionChanged event will not fire and when I test GridView.Behaviors.Selection.SelectedRows.Count, I always get 0 regardless of how many rows are selected.

In testing various scenarios, I removed the DataBind call and find that the row selection started working!  The event fired and the SelectedRows had the right rows.

However, if I don't call DataBind, Sorting stops working. 

Am I doing something wrong?  Is there a better approach?