Search code examples
c#asp.nettelerikradgrid

Close Telerik Radgrid Editform If Already Opened


I've spent the past hour or two trying to find a solution to what I think should be easy to do and something that I would think has been asked before, but perhaps I'm not using the correct terms.

I have a very basic RadGrid that allows rows to be expanded for editing or showing more stuff. Here is the GridEditCommandColumn I have inside of

<rad:GridEditCommandColumn EditText="+" UniqueName="EditCommandColumn" ItemStyle-Width="30" HeaderStyle-Width="30" />

Again, nothing special. When the grid loads, there's a "+" character for each row allowing it to expand. If I click on it, it correctly opens as it should. If I click another row, it closes the one I had open and opens the one I clicked on. Great, all is fine.

Now what I've been trying to search for is if I have a row already open and I click the "+" link again, I'd like this row to close if it's already open. Right now, it remains opened.

Am I the only one who's ever wanted it to close if you click it again if it's already open?


Solution

  • In our application we do something similar, however rather than clicking the plus button again, we click a cancel button. For this cancel button, we don't actually have any specific code, but we set the CommandName="Cancel" in the markup then check for CommandName in the item command event & write our code there. The grid is then bound, and the edit form will be closed. Sorry it doesn't answer your root question, but hopefully something to kick start you.

    Below is the sample event structure where you can filter with the CommandName & write your logic.

    protected void rg_ItemCommand(object sender, GridCommandEventArgs e)
    {            
        if (e.CommandName == "Cancel")
        {
          //custom logic here
        }
    }