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

RadGrid admin side in Modules edit/update problems

4 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 22 Jun 2010, 03:01 PM
Hi Team,

Always problems with RadGrids in admin side. This time is with pagin and automatic edit/update. I use one RadGrid ajaxified server side radgrid inside News Module Edit/Insert Template. The Dataset is external data.  I need to load and update one Dataset and after store. The Dataset is loading and the RadGrid is paging, but if you try to edit or Update any items the pager it come back to the first page and one item in the first at same level is edited or updated. I use preconised RadGrid Automatic sample and this issue has beed submit to RadGrid Forum but not found solution. Only items of first page can be Edited or Updated. I really need some help to fix this problem.

<telerik:RadGrid ID="PlanGrid" runat="server" Skin="WebBlue"  GridLines="None" Width="100%" OnNeedDataSource="PlanGrid_NeedDataSource"
OnItemCreated="PlanGrid_ItemCreated" OnUpdateCommand="PlanGrid_UpdateCommand" AutoGenerateColumns="False" AllowMultiRowEdit="True" ShowStatusBar="true" AllowPaging="True">
     <MasterTableView DataKeyNames="Week" Width="100%" CommandItemDisplay="Top" EditMode="InPlace" PageSize="14">
                   <Columns>
                     <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
                            <HeaderTemplate>
                             <asp:CheckBox id="headerChkbox" OnCheckedChanged="ToggleSelectedState" AutoPostBack="True" runat="server"></asp:CheckBox>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server"></asp:CheckBox>
                            </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn UniqueName="Week" SortExpression="Week" HeaderText="Sem." ReadOnly="true" DataField="Week" />   
                    <telerik:GridBoundColumn UniqueName="devise" SortExpression="devise" HeaderText="devise."       ReadOnly="true"DataField="devise" />    
                    <telerik:GridBoundColumn UniqueName="Days_1d"  HeaderText="Price"
                        DataField="Days_1d" >
                        <ItemStyle  Width="100px" />
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn UniqueName="Days_promo"  HeaderText="Discount(%)"
                        DataField="Days_promo" DataType="System.Int32">
                        <ItemStyle  Width="70px" />
                    </telerik:GridBoundColumn>             
                    
                    <telerik:GridEditCommandColumn UpdateText="Update" UniqueName="EditCommandColumn"
                        CancelText="Cancel" EditText="Edit">
                        <HeaderStyle Width="85px"></HeaderStyle>
                    </telerik:GridEditCommandColumn>
                </Columns>
                 <EditFormSettings CaptionFormatString="Semana {0}" CaptionDataField="Week" >
                    <FormTableItemStyle Width="100px" Height="29px"></FormTableItemStyle>
                    <FormTableStyle GridLines="None" CellSpacing="0" CellPadding="2"></FormTableStyle>
                    <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
                    <EditColumn ButtonType="ImageButton" />
                </EditFormSettings>
          
                </MasterTableView>
    <ClientSettings EnableRowHoverStyle="true">
       
    </ClientSettings>
     <PagerStyle Mode="NumericPages"></PagerStyle>
</telerik:RadGrid>

Page load (old issue fixed by ivan link the ajaxmanager to ajaxify)
RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);
if (ajaxManager != null)
{
    ajaxManager.AjaxSettings.Clear();
    ajaxManager.AjaxSettings.AddAjaxSetting(PlanGrid, PlanGrid);
}

 
protected void PlanGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            this.PlanGrid.DataSource = PlanningData; //is a Dataset
        }
  
     protected void PlanGrid_ItemPreRender(object sender, EventArgs e)
        {
            ((sender as GridDataItem)["CheckBoxTemplateColumn"].FindControl("CheckBox1") as CheckBox).Checked = (sender as GridDataItem).Selected;
  
        }
        protected void ToggleRowSelection(object sender, EventArgs e)
        {
            ((sender as CheckBox).Parent.Parent as GridItem).Selected = (sender as CheckBox).Checked;
        }
        protected void ToggleSelectedState(object sender, EventArgs e)
        {
            if ((sender as CheckBox).Checked == true)
            {
                foreach (GridDataItem dataItem in PlanGrid.MasterTableView.Items)
                {
                    (dataItem.FindControl("CheckBox1") as CheckBox).Checked = true;
                    dataItem.Selected = true;
                }
            }
            else
            {
                foreach (GridDataItem dataItem in PlanGrid.MasterTableView.Items)
                {
                    (dataItem.FindControl("CheckBox1") as CheckBox).Checked = false;
                    dataItem.Selected = false;
                }
            }
        }
        protected void PlanGrid_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            PlanGrid.MasterTableView.EditMode = GridEditMode.EditForms;
            GridEditableItem eeditedItem = e.Item as GridEditableItem;
            GridEditManager editMan = editedItem.EditManager;
  
            foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
            {
                if (column is IGridEditableColumn)
                {
                    IGridEditableColumn editableCol = (column as IGridEditableColumn);
                    if (editableCol.IsEditable)
                    {
                        IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
  
                        string editoreditorType = editor.ToString();
                        string editorText = "unknown";
                        object editorValue = null;
  
                        if (editor is GridTextColumnEditor)
                        {
                            editorText = (editor as GridTextColumnEditor).Text;
                            editorValue = (editor as GridTextColumnEditor).Text;
                        }
  
                        if (editor is GridBoolColumnEditor)
                        {
                            editorText = (editor as GridBoolColumnEditor).Value.ToString();
                            editorValue = (editor as GridBoolColumnEditor).Value;
                        }
  
                        if (editor is GridDropDownColumnEditor)
                        {
                            editorText = (editor as GridDropDownColumnEditor).SelectedText + "; " +
                                (editor as GridDropDownColumnEditor).SelectedValue;
                            editorValue = (editor as GridDropDownColumnEditor).SelectedValue;
                        }
  
                        try
                        {
                            DataRow[] changedRows = PlanningData.Tables[0].Select("Week= " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Week"]);
                            changedRows[0][column.UniqueName] = editorValue;
                            PlanningData.Tables[0].AcceptChanges();
                        }
                        catch (Exception ex)
                        {
                            PlanGrid.Controls.Add(new LiteralControl("<strong>Error '" + column.UniqueName + "'</strong> - " + ex.Message));
                            e.Canceled = true;
                            break;
                        }
                    }
                }
            }
            editedItem.Edit = false;
        }

Help.

4 Answers, 1 is accepted

Sort by
0
Ivan Dimitrov
Telerik team
answered on 22 Jun 2010, 04:15 PM
Hello Pierre,

You should set the CurrentPageIndex. You could take a look at


All the best,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Pierre
Top achievements
Rank 1
answered on 23 Jun 2010, 04:48 AM
Hi Ivan

I have added the ItemCommad event and tested but i have always same issue. I have tested with this same RadGrid in external UC in this admin as view  and the radGrid is working very well but not in the News template edited mode.
-Controled all registred UC in this template for session. many others sessions items used are working.
-I have searched Sessions interuptions using global asax session items and i have no interuption in session state.
-Later passed one session item from my template to another page and is ok.
-Session state is preserved and active during the test.
-I searched page headers declarations changes.
-No session.abort or clean() in codes or overrides
Past time i have used one IDisposable event and one clear all session but no more. I suspect some memory or cache issue?....
Could you perform a test using dataset as source NeedDatasource event in News Module Template.

regards.
protected void Page_Load(object sender, EventArgs e)
   {
       this.TEST.Text = Session["Testing"].ToString();
       RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(this.Page);
       if (ajaxManager != null)
       {
           //ajaxManager.AjaxSettings.Clear();
           ajaxManager.AjaxSettings.AddAjaxSetting(PlanGrid, PlanGrid);
           //ajaxManager.AjaxSettings.AddAjaxSetting(PlanGrid, LtItemsSelected);
       }
   }
   protected void PlanGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
   {
       this.PlanGrid.DataSource = PlanningData;
   }
    
   protected void PlanGrid_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
   {
      
       if (e.CommandName == RadGrid.InitInsertCommandName)
       {
           e.Canceled = true;
           Session["curPageIndex"] = e.Item.OwnerTableView.CurrentPageIndex;
           e.Item.OwnerTableView.InsertItem();
 
           e.Item.OwnerTableView.CurrentPageIndex = int.Parse(Session["curPageIndex"].ToString());
           e.Item.OwnerTableView.Rebind();
       }
       else if (e.CommandName == RadGrid.CancelCommandName && e.Item.OwnerTableView.IsItemInserted)
       {
           e.Item.OwnerTableView.CurrentPageIndex = int.Parse(Session["curPageIndex"].ToString());
       }
   }
   protected void PlanGrid_ItemPreRender(object sender, EventArgs e)
   {
       ((sender as GridDataItem)["CheckBoxTemplateColumn"].FindControl("CheckBox1") as CheckBox).Checked = (sender as GridDataItem).Selected;
 
   }
   protected void ToggleRowSelection(object sender, EventArgs e)
   {
       ((sender as CheckBox).Parent.Parent as GridItem).Selected = (sender as CheckBox).Checked;
   }
   protected void ToggleSelectedState(object sender, EventArgs e)
   {
       if ((sender as CheckBox).Checked == true)
       {
           foreach (GridDataItem dataItem in PlanGrid.MasterTableView.Items)
           {
               (dataItem.FindControl("CheckBox1") as CheckBox).Checked = true;
               dataItem.Selected = true;
           }
       }
       else
       {
           foreach (GridDataItem dataItem in PlanGrid.MasterTableView.Items)
           {
               (dataItem.FindControl("CheckBox1") as CheckBox).Checked = false;
               dataItem.Selected = false;
           }
       }
   }
   protected void PlanGrid_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
   {
       PlanGrid.MasterTableView.EditMode = GridEditMode.EditForms;
       GridEditableItem editedItem = e.Item as GridEditableItem;
       GridEditManager editMan = editedItem.EditManager;
 
       foreach (GridColumn column in e.Item.OwnerTableView.RenderColumns)
       {
           if (column is IGridEditableColumn)
           {
               IGridEditableColumn editableCol = (column as IGridEditableColumn);
               if (editableCol.IsEditable)
               {
                   IGridColumnEditor editor = editMan.GetColumnEditor(editableCol);
 
                   string editorType = editor.ToString();
                   string editorText = "unknown";
                   object editorValue = null;
 
                   if (editor is GridTextColumnEditor)
                   {
                       editorText = (editor as GridTextColumnEditor).Text;
                       editorValue = (editor as GridTextColumnEditor).Text;
                   }
 
                   if (editor is GridBoolColumnEditor)
                   {
                       editorText = (editor as GridBoolColumnEditor).Value.ToString();
                       editorValue = (editor as GridBoolColumnEditor).Value;
                   }
 
                   if (editor is GridDropDownColumnEditor)
                   {
                       editorText = (editor as GridDropDownColumnEditor).SelectedText + "; " +
                           (editor as GridDropDownColumnEditor).SelectedValue;
                       editorValue = (editor as GridDropDownColumnEditor).SelectedValue;
                   }
 
                   try
                   {
                       DataRow[] changedRows = PlanningData.Tables[0].Select("Week = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Week"]);
                       changedRows[0][column.UniqueName] = editorValue;
                       PlanningData.Tables[0].AcceptChanges();
                   }
                   catch (Exception ex)
                   {
                       PlanGrid.Controls.Add(new LiteralControl("<strong>No pudo definir el valor de '" + column.UniqueName + "'</strong> - " + ex.Message));
                       e.Canceled = true;
                       break;
                   }
               }
           }
       }
       editedItem.Edit = false;
   }

Add this code to Edit Mode of NewItemEdit template
<telerik:RadGrid ID="PlanGrid" runat="server" Skin="Vista"  GridLines="None" Width="100%" OnNeedDataSource="PlanGrid_NeedDataSource"
 AutoGenerateColumns="False" AllowMultiRowEdit="True" ShowStatusBar="true" AllowPaging="True" OnItemCommand="PlanGrid_ItemCommand"
OnUpdateCommand="PlanGrid_UpdateCommand" AllowAutomaticUpdates="True" PageSize="14">
     <MasterTableView DataKeyNames="Week" Width="100%" CommandItemDisplay="Top" EditMode="InPlace" >
                   <Columns>
                    <telerik:GridEditCommandColumn  ButtonType="ImageButton" UniqueName="EditCommandColumn">
                        <ItemStyle CssClass="MyImageButton" />
                    </telerik:GridEditCommandColumn>
                     <telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn">
                            <HeaderTemplate>
                             <asp:CheckBox id="headerChkbox" OnCheckedChanged="ToggleSelectedState" AutoPostBack="True" runat="server"></asp:CheckBox>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server"></asp:CheckBox>
                            </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn UniqueName="Week" SortExpression="Week" HeaderText="Sem." ReadOnly="true"
                        DataField="Week" />
                    <telerik:GridBoundColumn UniqueName="Days_1d"  HeaderText="Price"
                        DataField="Days_1d" >
                        <ItemStyle  Width="100px" />
                    </telerik:GridBoundColumn>
                     <telerik:GridBoundColumn UniqueName="Days_promo"  HeaderText="Discount(%)"
                        DataField="Days_promo" DataType="System.Int32">
                        <ItemStyle  Width="70px" />
                    </telerik:GridBoundColumn>            

                </Columns>
                <CommandItemTemplate>
                       <asp:Label runat="server" ID="Label3">Define tus precios</asp:Label>
                       <br />
                       <asp:Label runat="server" ID="lbPrice" Width="60">Precios</asp:Label>
                 </CommandItemTemplate>
                   <EditFormSettings ColumnNumber="2" CaptionDataField="Week" CaptionFormatString="Edit properties of Week {0}">
                       <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                        <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                        <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                            Width="100%" />
                        <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
                        <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                        <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update week"
                            UniqueName="EditCommandColumn1" CancelText="Cancel">
                        </EditColumn>
                        <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                    </EditFormSettings>
          
                </MasterTableView>
    <ClientSettings EnableRowHoverStyle="true">
    </ClientSettings>
    <PagerStyle  Mode="NextPrevAndNumeric" />    
</telerik:RadGrid>
0
Jason
Top achievements
Rank 1
answered on 13 Dec 2010, 10:49 PM
I'm using a RadGrid with editmode=editforms the "add new record" form displays fine but the edit form display at the buttom of the grid and is not visible unless I scroll down...How can I get the two forms display at the top of the grid?
0
Iana Tsolova
Telerik team
answered on 20 Dec 2010, 10:20 AM
Hi,

To Pierre: Try setting the AllowAutomaticUpdates property of the grid to false and see if it makes any difference. Note that you can use automatic updates only when the grid is bound to DataSourceControl, like SqlDataSource, LinqDataSource, etc.,  which is configured to perform update operations. When the grid is bound through the NeedDataSource event, you need to handle the update command manually, as in this article for instance.

To Christopher: The edit form should open just below the corresponding edited item. Furthermore, the edit form is part of the edited grid data item, therefore it cannot be displayed elsewhere. Can you confirm this is the behavior in your case? If not, providing additional information on your grid setup and scenario might help us get to the source of the problem.

Kind regards,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Pierre
Top achievements
Rank 1
Answers by
Ivan Dimitrov
Telerik team
Pierre
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or