Only edit one row at a time

6 posts, 0 answers
  1. Carl-Johan
    Carl-Johan avatar
    22 posts
    Member since:
    May 2008

    Posted 29 Jun 2010 Link to this post

    Hi,

    I would like to close all rows that are in edit-mode when i click on edit one another row. That way i can only edit one row at a time (locks better).

    I would also like this to work the same way when i insert a new row.

    How do i do that?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Jun 2010 Link to this post

    Hello Carl-Johan,

    If you want only one row in edit mode you can set AllowMultiRowEdit Property of RadGrid as false. You can refer the following Forum post which explains how to hide editform when clicking insert and vice versa.

    Stop Edit and Insert from displaying at the same time

    Thanks,
    Princy.




  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Carl-Johan
    Carl-Johan avatar
    22 posts
    Member since:
    May 2008

    Posted 29 Jun 2010 Link to this post

    Hi,

    Thank you for the quick reply.

    The "AllowMultiRowEdit" works great.

    But if you have a MasterTable/Childtable it only works on one table at a time.

    So if I have the MasterTable in editmod, expand the MasterTable, sets a childrow in editmode the MasterTable is still in editmode.
    Is it possible to solve this.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Jun 2010 Link to this post

    Hello Carl-Johan,

     Here is the sample code that i did in my application to achieve this functionality. In ItemCommand event catch the operation (Insert/Edit), GridTableViewName (Master/DetailTable), and row index of MaterTable and DetailTable by using Session variables. Then in PreRender event, based on the value in Session variable show the insert/edit form in  MasterTable/DetailTable accordingly. I know the code is too grievous, but at present I can't find an alternate method for this.

    ASPX:
    <MasterTableView Name="Master" runat="server" AutoGenerateColumns="true" DataKeyNames="EmployeeID"  
            CommandItemDisplay="Top">  
            <DetailTables>  
                <telerik:GridTableView Name="GridTableView1" runat="server" AutoGenerateColumns="true"  
                    DataKeyNames="EmployeeID" CommandItemDisplay="Top" DataSourceID="SqlDataSource2">  
                    <ParentTableRelation>  
                        <telerik:GridRelationFields DetailKeyField="EmployeeID" MasterKeyField="EmployeeID" />  
                    </ParentTableRelation>  
                    <Columns>  
                        <telerik:GridEditCommandColumn>  
                        </telerik:GridEditCommandColumn>  
                    </Columns>  
                </telerik:GridTableView>  
            </DetailTables>  
            <Columns>  
                <telerik:GridEditCommandColumn UniqueName="EditColumn">  
                </telerik:GridEditCommandColumn>  
            </Columns>  
     </MasterTableView>  

    C#:
      protected void Page_Load(object sender, EventArgs e) 
        { 
            Session["rowIndex"] = 0; 
            Session["detailIndex"] = 0; 
            Session["operation"] = 0; 
            Session["tableName"] = 0; 
        } 
     
     protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
        { 
            Session["operation"]= e.CommandName; 
            Session["tableName"] = e.Item.OwnerTableView.Name; 
            if ((e.CommandName == "InitInsert" || e.CommandName == "Edit")) 
            { 
                if (e.Item.OwnerTableView.Name == "GridTableView1"
                { 
                    Session["rowIndex"] = e.Item.OwnerTableView.ParentItem.ItemIndex; 
                    Session["detailIndex"] = e.Item.ItemIndex; 
                } 
                else 
                { 
                    Session["rowIndex"] = e.Item.ItemIndex; 
                } 
            } 
       } 
     
     protected void RadGrid1_PreRender(object sender, EventArgs e) 
        {      
            int rowIndex = Convert.ToInt16(Session["rowIndex"].ToString()); 
            int detailIndex = Convert.ToInt16(Session["detailIndex"].ToString()); 
            if (Session["operation"].ToString()=="InitInsert")             
            { 
                if (Session["tableName"].ToString() == "GridTableView1"
                { 
                    RadGrid1.MasterTableView.IsItemInserted = false
                    RadGrid1.EditIndexes.Clear(); 
                    RadGrid1.MasterTableView.Rebind(); 
                    RadGrid1.MasterTableView.Items[rowIndex].Expanded = true
                    (RadGrid1.MasterTableView.Items[rowIndex] as GridDataItem).ChildItem.NestedTableViews[0].IsItemInserted = true
                    (RadGrid1.MasterTableView.Items[rowIndex] as GridDataItem).ChildItem.NestedTableViews[0].Rebind(); 
                 } 
                if (Session["tableName"].ToString() == "Master"
                { 
                    RadGrid1.EditIndexes.Clear(); 
                    RadGrid1.MasterTableView.Rebind(); 
                    RadGrid1.MasterTableView.IsItemInserted = true
                } 
            } 
            if(Session["operation"].ToString()=="Edit"
            { 
                if (Session["tableName"].ToString() == "GridTableView1"
                { 
                    RadGrid1.MasterTableView.IsItemInserted = false
                    RadGrid1.EditIndexes.Clear(); 
                    RadGrid1.MasterTableView.Rebind(); 
                    RadGrid1.MasterTableView.Items[rowIndex].Expanded = true
                    (RadGrid1.MasterTableView.Items[rowIndex] as GridDataItem).ChildItem.NestedTableViews[0].Items[detailIndex].Edit = true
                    (RadGrid1.MasterTableView.Items[rowIndex] as GridDataItem).ChildItem.NestedTableViews[0].Rebind(); 
                } 
                if (Session["tableName"].ToString() == "Master"
                { 
                    RadGrid1.MasterTableView.IsItemInserted = false
                    RadGrid1.MasterTableView.Rebind(); 
                    RadGrid1.MasterTableView.Items[rowIndex].Edit = true
                } 
            } 
        } 

    Hope this helps you,
    Princy.
  6. zel
    zel avatar
    33 posts
    Member since:
    Aug 2010

    Posted 29 Sep 2010 Link to this post

    Hi Princy,

    I have the same problem with Carl. I hope that there will be a property to set "allow only one master row expanded". So that, there is no need to code anymore.

    Regards,
    Lyzel
  7. Vasssek
    Vasssek avatar
    143 posts
    Member since:
    Aug 2010

    Posted 13 Feb 2012 Link to this post

    Hello everybody,

    I know this is a quite old thread, but... Here is my solution how to deal with only one edit row at a time, no matter it is come from master or detail table. It's been done all in one event - RadGrid1_ItemCommand. Radgrid edit mode has to be set as EditMode="InPlace".
    protected void RadGridx_1_OnItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.EditCommandName)
        {
            RadGridx_1.MasterTableView.IsItemInserted = false;
        }
        else if (e.CommandName == RadGrid.InitInsertCommandName)
        {
            RadGridx_1.MasterTableView.ClearEditItems();
        }
        else if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem && !e.Item.Expanded)
        {
            RadGridx_1.MasterTableView.IsItemInserted = false;
            RadGridx_1.EditIndexes.Clear();
            RadGridx_1.MasterTableView.Rebind();
            RadGridx_1.MasterTableView.Items[e.Item.ItemIndex].Expanded = true;
        }
    }

    I hope it helps somebody from big Telerik community...

    Vasssek
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017