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?
Hello gregehr,
Thank you for posting in our community.
I've made a sample based on your code in order to try reproducing the issue, however I was not able to.
I've added button and attached a click event to it. Then on row selection, RowSelectionChanged event fires at first, then the button click event fires and the selected rows count is available in the click event.
I'm attaching you the sample that I've used to experiment with.
Please take a look at it and feel free to modify it in order to reproduce the behavior that you're experiencing on your side. Then send it back to me.
If you have any further questions, please let me know.
Sincerely,
Tsanna
Thank you for your quick response.
Your code did give me a hint that helped me track down the problem. I'll post it here in case it might help someone else.
Since the call to DataBind was making the difference, I decided to trace through what events are triggered on binding data.
I have code in the OnInitializeBand event of the grid to create columns summaries (among other things).
After I add the ColumnSummaryInfo to Behaviors.SummaryRow.ColumnSummaries, I thought I had to call grid.RefreshBehaviors to have them take effect.
It appears that this is not necessary for the summaries and it was causing the problem of RowSelectionChanged not firing.
Thank you for your feedback.
I'm glad that you were able to resolve your issue.
Please feel free to share you experience in the forum in order it could be helpful for other that have similar issues.
If you need any further assistance regarding this matter, do not hesitate to contact me.