We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Various selection/display issues

Hi

I have a few issues with the asp.net web forms Grid control, id appreciate some help please

1) the ServerRowDeselected event never seems to fire

2) when I click the header to sort it deselects the current row (so none are selected) but as it doesn’t seem to raise an event I can’t reset my internal ‘SelectedIndex’ flag to -1, how do I do this?. Im sure at sone time clicking the header kept the current item selected, but I think I must have changed a setting somewhere or my update panels are getting in the way – any ideas?

3) I can’t find how to check what the current grid selected row or index is programatically in my c# code behind - all examples seem to Do it in an event. And am pretty much a newbie to javascript and need to learn more, so if you are giving a javascript example please also tell me how I get the appropriate values into my code behind

4) How do I programmatically select a row on one of the grid pages and ensure its visible, eg after a new row is inserted mid way in the list

ive attached my test page to give you an idea where im at

many thanks in advance

Bob


Attachment: GridIssues_ad271071.zip

1 Reply

PK Padmavathy Kamalanathan Syncfusion Team August 7, 2019 04:50 PM UTC

Hi Bob, 
 
Thanks for contacting Syncfusion Forums. 
 
QUERY1: the ServerRowDeselected event never seems to fire 
 
From your query we understand that, the OnServerRowDeselected event doesn’t fires. When you use both OnServerRowSelected, OnServerRowDeselected event , select a row, the OnServerRowSelected event will be triggered. When you select another row, the OnServerRowDeselected event will not be triggered for the deselected row, instead the  OnServerRowSelected event will be triggered for newly selected row. This is the behavior of grid. 
 
QUERY2: when I click the header to sort it deselects the current row (so none are selected) but as it doesn’t seem to raise an event I can’t reset my internal ‘SelectedIndex’ flag to -1 
 
When you select and sort the grid, the grid rows get sorted, which means the row you have selected could have been in different page. After sorting, you no longer do any operation with that selected row, since it may not be in the current page. You have mentioned that you need to set internal flag. Please do clarify your requirement and scenario, so that we could help you to achieve it. 
 
QUERY3: I can’t find how to check what the current grid selected row or index is programmatically in my c# code behind 
 
You can set a button, bind OnClick event to it, and get the current grid selected row from GridId.SelectedRowIndex in code behind. 
 
Please refer the below code snippet, 
 
 
            <ej:Button ID="btn_Click" runat="server" OnClick="btn_Click_Click" Size="Normal" Text="Click to Select"></ej:Button> 
            <ej:Grid ID="OrdersGrid" runat="server"  
                   ----------- 
                <Columns> 
                      ---- 
                </Columns> 
            </ej:Grid> 
 
In code behind 
 
        protected void btn_Click_Click(object Sender, ButtonEventArgs e) 
        { 
            if(OrdersGrid.SelectedRowIndex != -1) {  
               // GridId. SelectedRowIndex will give selected rownindex 
                 -------- 
            } 
        } 
 
 
 
Please refer the below screenshot, 
 
 
 
QUERY4: How do I programmatically select a row on one of the grid pages and ensure its visible 
 
For selecting the last added row, you can call SelectRows method and pass the index of newly added record to that method in actioncomplete event with args.requestType as “save” and args.action as “add” to select the newly added row. 
 
Please refer the below code snippet, 
 
 
   <script> 
        function complete(args) { 
           if (args.requestType == "save" && args.action == "add") { 
              this.selectRows(index); // index= index of newly added row 
                        } 
                    } 
   </script> 
 
 
 
If you are unable to achieve this result, please do clarify us how you are inserting row in grid, so that we can help you to achieve your query. 
 
If you have further queries, please get back to us. 
 
Regards, 
Padmavathy Kamalanathan 


Loader.
Live Chat Icon For mobile
Up arrow icon