Current filter:
                                You should refresh the page.
                                0
                                  • Hi

                                    I am trying to automatically display the detail row if only 1 record is returned from either the initial query or after a filter. I am using the following code to do so:

                                    	
                                    [C#]
                                    protected void Grid_DataBound(object sender, EventArgs e) { if (Grid.VisibleRowCount == 1) Grid.DetailRows.ExpandRow(0); }
                                    This is working if the datasource only contains 1 record but it does not work for filtering. If i put a breakpoint in this method then after the filter, the VisibleRowCount is the original DataSource count. If I then clear the filter, VisibleRowCount is now equal to 1 and expands the row but more than one record is displayed so it is doing it too late. I have attached a sample project.

                                    Is this a bug or should my code be in a different event?

                                    Thanks,
                                    Renae



                                VisibleRowCount.zip
                                You must  log in  or  register  to leave comments

                                1 Solution

                                0

                                Hello,

                                Please handle the BeforeGetCallbackResult event instead.

                                • Renae 01.21.2013

                                  This works for the filtering but doesn't for when the datasource is first set so i've left it in both events. This does mean it fires after clearing the filter (as the databound event still thinks VisibleRowCount is 1) but that row will already be expanded so isn't a big deal.

                                • Hi,

                                  >>This works for the filtering but doesn't for when the datasource is first set
                                  This behavior is caused by the fact that the ASPxGridView.BeforeGetCallbackResult event fires only on the grid's callbacks and doesn't fire either when the page is loaded for the first time or on postbacks. So, to avoid the double call of the ExpandRow method, use the ASPxWebControl.IsCallback property to check if the grid's callback was sent:

                                  protected void Grid_DataBound(object sender, EventArgs e) {
                                      if (!Grid.IsCallback && Grid.VisibleRowCount == 1)
                                          Grid.DetailRows.ExpandRow(0);
                                  }
                                  

                                You must  log in  or  register  to leave comments
                                You must  log in  or  register  to leave an answer

                                Is your intention to post an answer to your own question?

                                • If so, then proceed.
                                • If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
                                • If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.