Hi.
I'm using Visual Studio 2012 and NetAdvantatge 12.2 ASP.NET CLR 4
I use a WebHierarchicalDataGrid with an additional band. I allowed selection for the whole grid, but when I try to get the selected row (in server side), the SelectedRows.Counts is always 0.
This is the control definition:
<ig:WebHierarchicalDataGrid ID="Grid" runat="server" Width="600px" AutoGenerateBands="False" AutoGenerateColumns="False" DataSourceID="DSEstocs" Key="Articles" DataKeyFields="CodigoArticulo">
<Columns> .... <Columns/>
<Bands> .... <Bands/>
<Behaviors>
<ig:Selection CellClickAction="Row" RowSelectType="Single"/>
<Behaviors/>
<ig:WebHierarchicalDataGrid/>
And when I try to get the selected row:
if (Grid.Behaviors.Selection.SelectedRows.Count > 0)
{
...
}
else if (Grid.Bands[0].BandHasBehaviors && Grid.Bands[0].Behaviors.Selection.SelectedRows.Count > 0)
SelectedRows.Count returns always 0.
Can you help me ?
Thanks in advance.
Hello Joan,
Thank you for posting in our community.
I assume that you need to set AutoPostBackFlags RowSelectionChanged to true as follows:
<ig:Selection RowSelectType="Single" CellClickAction="Row" Enabled="true">
<AutoPostBackFlags RowSelectionChanged="true" />
</ig:Selection>
</Behaviors>
Note that Selection behavior doesn't make post back to the server by default unless it is set explicitly. If you have handled the RowSelectionChanged event you need a post back to the server to get the count of the selected rows. Attached is a sample which demonstrates similar scenario. Please let me know if this helps you.
Sincerely,
Tsanna
Hi Tsanna.
No, I don't need to handle the RowSelection event, I want to know anytime wich are the selected rows collection.
The property: Grid.Behaviors.Selection.SelectedRows.Count works correctly for a single band grid, but neither Grid.Behaviors.Selection.SelectedRows.Count nor Grid.Bands[0].Behaviors.Selection.SelectedRows.Count works if I use more than one band.
Thanks for your help.
Regards
Note that the earliest possible event that you can access the selected rows count is RowSelectionChanged event. You will be unable to access it through Page_Init or Page_Load events because the SelectedRowCollection properties are not fully loaded during the page life cycle. Note that at the same moment you can’t select rows both from the parent and the child grid. On RowSelectionChanged event or on some late page life cycle event (for instance Page_PreRender) there is a way to keep track of which sender has raised the current event, whether the parent grid or the child grid. This could be achieved during debugging if you inspect the current sender’s key property. However even the child grid has raised the selection changed event, note that the selected rows count would be returned for the parent grid. If you want to get the selected rows from the child grid, then you need to iterate through the grid’s row collection and access the current selected child bands through the RowIsland Selection Behaviors, for instance:
protected void WebHierarchicalDataGrid1_RowSelectionChanged(object sender, Infragistics.Web.UI.GridControls.SelectedRowEventArgs e)
var firstChildBandSelectedRows = WebHierarchicalDataGrid1.GridView.Rows[0].RowIslands[0].Behaviors.Selection.SelectedRows.Count;
Please refer also to the following documentation article about the Selection behavior of the WebHierarchicaDataGrid: http://help.infragistics.com/Help/NetAdvantage/ASPNET/2012.1/CLR4.0/html/WebHierachicalDataGrid_Selection.html.
If you need more assistance, please feel free to contact me.
I'm just checking if you need any further assistance with this case, please feel free to contact me.