This is a migrated thread and some comments may be shown as answers.

RadGrid in place edit

4 Answers 111 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vinayak
Top achievements
Rank 1
Vinayak asked on 03 Jul 2013, 02:09 PM
How to persist row in editable mode in radgrid, on page size change?
Scenario:- In my radgrid i have 10 records with page size of 5 records. I am on second page to edit 3rd record(4th index).
Now I change page size from 5 to 10 and the record in edit mode changes. It takes 3rd record among 10.
Ideally 9th row should remain in edit mode.
How to achive this?

Thanks in advance

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 05 Jul 2013, 08:49 AM
Hi Vinayak,

Can u please try the following code snippet and check if it helps.

ASPX:
<telerik:RadGrid ID="Radgrid1" runat="server" PageSize="5" DataSourceID="SqlDataSource2"
    AllowPaging="true"  AllowAutomaticUpdates="true" >  
    <MasterTableView AutoGenerateColumns="false" DataSourceID="SqlDataSource2" DataKeyNames="OrderID"
        CommandItemDisplay="Top">  
        <Columns>
            <telerik:GridEditCommandColumn ></telerik:GridEditCommandColumn>
            <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" UniqueName="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" UniqueName="CustomerID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView
</telerik:RadGrid>

Thanks,
Princy
0
Vinayak
Top achievements
Rank 1
answered on 05 Jul 2013, 09:25 AM
0
Princy
Top achievements
Rank 2
answered on 05 Jul 2013, 10:55 AM
Hi Vinayak,

Please try the following code snippet.It works fine at my end.It persists the edit mode in page size change .Hope this helps.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"   PageSize="5" AllowAutomaticUpdates="True" AllowPaging="True"
    AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnPreRender="RadGrid1_PreRender"
    OnEditCommand="RadGrid1_EditCommand" OnPageSizeChanged="RadGrid1_PageSizeChanged">
    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
    <MasterTableView  CommandItemDisplay="TopAndBottom" DataKeyNames="ProductID"
        DataSourceID="SqlDataSource1" AutoGenerateColumns="False">
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
            </telerik:GridEditCommandColumn>
            <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName"
                UniqueName="ProductName" ColumnEditorID="GridTextBoxColumnEditor1">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
public static string dataKey = "";
   bool isPageSizeChanged = false;
   protected void RadGrid1_PreRender(object sender, EventArgs e)
   {
       if (isPageSizeChanged)
       {
           foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
           {
               string value = item.GetDataKeyValue("ProductID").ToString();
               if (value == dataKey)
               {
                   item.Edit = true;
                   break;
               }
           }
           isPageSizeChanged = false;
           RadGrid1.Rebind();
 
       }
   }
   protected void RadGrid1_EditCommand(object sender, GridCommandEventArgs e)
   {
       GridDataItem editItem = (GridDataItem)e.Item;
       dataKey = editItem.GetDataKeyValue("ProductID").ToString();
   }
   protected void RadGrid1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
   {
       isPageSizeChanged = true;
   }

Thanks,
Princy
0
Vinayak
Top achievements
Rank 1
answered on 05 Jul 2013, 01:33 PM
Thanks Princy,
it's working fine.
Tags
General Discussions
Asked by
Vinayak
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Vinayak
Top achievements
Rank 1
Share this question
or