I placed a grid on a form, added datasource, data is displayed properly. User selects a row and clicks some link button.Inside my code behind I would like to get access to selected row.But my_grid.Behaviors.Selection.SelectedRows.Count = 0.What is wrong with my code?
Grid:
<ig1:WebHierarchicalDataGrid ID="my_grid" runat="server" AutoGenerateBands="False" AutoGenerateColumns="False" DataKeyFields="ID" DataMember="ObjectDataSourceKlasy_DefaultView" DataSourceID="KlasyDataSource" Height="350px" Key="ObjectDataSourceKlasy_DefaultView" Width="400px"> <Bands> <ig1:Band AutoGenerateColumns="False" DataMember="ObjectDataSourceDaneKlas_DefaultView" Key="ObjectDataSourceDaneKlas_DefaultView"> <Columns> //... </Columns> </ig1:Band> </Bands> <Columns> </Columns> <Behaviors> <ig1:Activation> </ig1:Activation> <ig1:EditingCore> <Behaviors> <ig1:CellEditing> </ig1:CellEditing> </Behaviors> </ig1:EditingCore> <ig1:Paging> </ig1:Paging> <ig1:RowSelectors> </ig1:RowSelectors> <ig1:Selection RowSelectType="Single"> </ig1:Selection> <ig1:Sorting> </ig1:Sorting> </Behaviors> </ig1:WebHierarchicalDataGrid>
Hello Arthur,On which event you are trying to get the selected row? When you make a postback this collection will be empty till the load phase is over. Our grid should be fully loaded with data and then if you like to access the collection in PreRender event it should be filled with all the rows and row count should be the expected one.
I do that on event of clicking link button -> protected void button_Click(object sender, EventArgs e)
Hello Arthur,
If the selection changed event is fired over an ajax postback handled by the grid , then no. The reason is that over the ajax callback of the grid only changes made to the grid itself will be reflected. If you disable the grid’s ajax (EnableAjax=false) , wrap the grid and the combo in an update panel and set an autopostback flag for the row selection changing then over the ajax callback both the grid and the combo can be updated.
If you need more information on what’s the difference between the grid’s ajax and using an update panel to handle the ajax requests you can refer to the following forum thread:
http://es.infragistics.com/community/forums/p/68145/345224.aspx#345224
Let me know if you have any questions.
Best Regards,
Maya Kirova
Developer Support Engineer
Infragistics, Inc.
http://es.infragistics.com/support
Thank you vey much - it works! It should really be somewhere in manuals with bold, red and blinking font :)
Could you help me with another (small) thing ?
There is combo somewhere on the form. I would like to populate its content based on grid selection.
If I use function -> protected void my_grid_RowSelectionChanged(object sender, SelectedRowEventArgs e) and call DataBind on that combo it will get refreshed but only after postback. Is there a way to force DataBind on that combo immediately from grid event handler?
Hello Arthur ,
Try getting the selected rows from the grid view. For example:
this.WebHierarchicalDataGrid1.GridView.Behaviors.Selection.SelectedRows.Count;
Let me know if you come across any issues with that.