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

Edit Update auto always fire firt page items

1 Answer 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 12 Jun 2010, 10:47 PM
Hi team,

I have one problem to fix this issue with my simple grid (no hierarchie) using one Dataset as source. The Dataset is preserved using session (week_id, price, discount). The grid generate four ajax pages and pager is working as normal (next previous and go to page). I use Edit Inline or other edit modes are causing same problem the item opened to be updated is always at firt page same level. I have tested other scenarios using codes used in demo but is similar. using last Q. Ajax is registred backside joining a masterpage radscriptmanager. Thanks. Romi

<telerik:RadGrid ID="PlanGrid" runat="server" Skin="Vista"  GridLines="None" Width="100%" OnNeedDataSource="PlanGrid_NeedDataSource" 
                                             AutoGenerateColumns="False" AllowMultiRowEdit="True" ShowStatusBar="true" AllowPaging="True" 
                                            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="Week" 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> 
                                                               <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> 
 
 
//CODE 
 
    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
        } 

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 17 Jun 2010, 07:02 AM
Hi Pierre,

I reviewed the code snippet, and it looks correct. If the issue persists, you can open a formal support ticket, and send us a small working project, for additional review and testing. We will debug the sample locally, and get back to you with more information on the matter.

Regards,
Yavor
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.
Tags
Grid
Asked by
Pierre
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or