Close Telerik Radgrid Change the form if it is already open

I spent the last hour or two trying to find a solution to what, in my opinion, should be easy to do, and something that I was thinking about was asked before, but maybe I'm not using the right conditions.

I have a very simple RadGrid that allows me to expand rows for editing or displaying more materials. Here is the GridEditCommandColumn inside

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

Again, nothing special. When the grid loads, there is a “+” symbol for each row, allowing it to expand. If I click on it, it will open correctly, as it should. If I click another line, it closes the one I opened and opens the one I clicked on. Great, everything is in order.

Now what I was trying to find is if I already have a line and I click the "+" link again, I would like this line to close if it is already open. Now it remains open.

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

+5
source share
3 answers

- , , "", "". - , CommandName="Cancel" , CommandName item . , . , , , , - .

, CommandName .

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

dstepan, . GridEditCommandColumn .

<rad:GridTemplateColumn UniqueName="ExpandRow">
   <ItemTemplate>
      <asp:Button ID="btnExpand" CommandName="ExpandRow" CommandArgument="<%# Container.ItemIndex %>" Text="+" runat="server" />
    </ItemTemplate>
 </rad:GridTemplateColumn>

protected void rg_ItemCommand(object sender, GridCommandEventArgs e)
    {            
        if (e.CommandName == "ExpandRow")
        {
            GridDataItem item = rg.Items[int.Parse(e.CommandArgument.ToString())];

            item.Edit = item.Edit ? false : true; // If it already in edit mode, change it to false. If not, set it to true

            rg.Rebind();
        }
    }
+4

Try using the code snippet below.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.EditCommandName)
    {
        RadGrid1.MasterTableView.ClearEditItems();
    }
}
+3
source

All Articles