Grid update command not working

5 posts, 0 answers
  1. Sandip Patil
    Sandip Patil avatar
    2 posts
    Member since:
    May 2010

    Posted 21 Nov 2011 Link to this post

    Hi,

    i am using this code for update grid row text but it is not working

    HTML CODE
    /////
     <div id="divListGrid" class="floatLeft" style="width: 30%">
            <cc1:PGrid runat="server" ID="datalist" AllowPaging="true" AllowSorting="true" PageSize="25">
                <MasterTableView AutoGenerateColumns="False" DataKeyNames="SearchHeader, CreatedDateTime"
                    TableLayout="Fixed" ClientDataKeyNames="SearchHeader, CreatedDateTime,HeaderID"
                    EditMode="EditForms">
                    <Columns>
                        <cc1:PGridBoundColumn DataField="SearchHeader" HeaderText="<%$ Resources:demo,LABEL_SEARCH_HEADER  %>"
                            SortExpression="SearchHeader" UniqueName="SearchHeader" ColumnEditorID="GridTextBoxColumnEditor1">
                            <HeaderStyle Width="30%" />
                            <ItemStyle Wrap="true" />
                        </cc1:PGridBoundColumn>
                        <cc1:PGridBoundColumn DataField="CreatedDateTime" HeaderText=""
                            SortExpression="CreatedDateTime" ReadOnly="true" UniqueName="CreatedDateTime"
                            DataFormatString="{0:dd-MMM-yyyy}">
                            <HeaderStyle Width="20%" />
                            <ItemStyle Wrap="true" />
                        </cc1:PGridBoundColumn>
                        <telerik:GridEditCommandColumn EditText="<%$ Resources:demo,LABEL_EDIT %>" ItemStyle-CssClass="demo_Secondary_Button" >
                            <HeaderStyle Width="11%" Wrap="true"/>
                        </telerik:GridEditCommandColumn>
                           <cc1:PGridTemplateColumn>
                            <ItemTemplate>
                              <cc1:PImageButton Text="<%$ Resources:demo,LABEL_DELETE %>" ID="cmdDelete" Visible="true" CommandArgument="Delete"
                                     runat ="server" OnClientClick="javascript:removeHeader(); return false;"  ImageUrl="~/Images/transparent.png"
                                      CssClass="ui-icon ui-icon-trashdemoImage floatLeft" ToolTip="<%$ Resources:demo,LABEL_DELETE %>"  />

                            </ItemTemplate>
                            <HeaderStyle Width="11%" />
                        </cc1:PGridTemplateColumn>
                    </Columns>
                    <EditFormSettings EditColumn-ItemStyle-CssClass ="demo_Secondary_Button">
                        <EditColumn UpdateText="<%$ Resources:demo,LABEL_UPDATE %>" UniqueName="EditCommandSearchHeader"
                            CancelText="<%$ Resources:demo,LABEL_CANCEL %>">
                        </EditColumn>
                    </EditFormSettings>
                </MasterTableView>
                <ClientSettings>
                    <Selecting AllowRowSelect="true" />
                    <ClientEvents OnRowSelected="RowSelected" OnRowMouseOver="RowMouseOver" />
                </ClientSettings>
            </cc1:PGrid>
            <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="100px" />
        </div>
    </div>

    //javascript

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">

            var hasChanges, inputs, editedRow, currentRowIndex, gridSearchResultCurrentRowIndex;
            function loadItems() {
                if (currentRowIndex > -1) {
                    var masterTableView = $find("<%= datalist.ClientID %>").get_masterTableView();
                    var dataItem = masterTableView.get_dataItems()[currentRowIndex];
                    masterTableView.clearSelectedItems();
                    dataItem.set_selected(true);
                }
            }
            function RowDblClick(sender, eventArgs) {
                editedRow = eventArgs.get_itemIndexHierarchical();
                $find("<%= datalist.ClientID %>").get_masterTableView().editItem(editedRow);
            }

            function RowMouseOver(sender, eventArgs) {
                currentRowIndex = eventArgs.get_itemIndexHierarchical();
            }

            //        function RowCommand(sender, eventArgs) {
            //            debugger;
            //            if (currentRowIndex > -1) {
            //                if (eventArgs.get_commandName() == "Edit") {
            //                    $find("<%= datalist.ClientID %>").get_masterTableView().editItem(currentRowIndex);
            //                }
            //            }

            //        }

            function RowSelected(sender, eventArgs) {

                var headerID = eventArgs.getDataKeyValue("HeaderID");
                var panel = $find("<%= XmlHttpPanelSaveHistory.ClientID %>");
                panel.set_value(headerID);

            }

            function RowClick(sender, eventArgs) {

                if (hasChanges && editedRow) {
                    hasChanges = false;

                    if (confirm("Update changes?")) {

                        $find("<%= datalist.ClientID %>").get_masterTableView().updateItem(0);
                    }
                }
            }




            function GridCreated(sender, eventArgs) {

                var gridElement = sender.get_element();
                var elementsToUse = [];
                inputs = gridElement.getElementsByTagName("input");
                for (var i = 0; i < inputs.length; i++) {
                    var lowerType = inputs[i].type.toLowerCase();
                    if (lowerType == "hidden" || lowerType == "button") {
                        continue;
                    }

                    Array.add(elementsToUse, inputs[i]);
                    inputs[i].onchange = TrackChanges;
                }

                setTimeout(function () { if (elementsToUse[0]) elementsToUse[0].focus(); }, 100);
            }

            function TrackChanges(e) {
                hasChanges = true;
            }


            function removeHeader(rowIndex) {
                rowIndex = currentRowIndex;
                if (rowIndex > -1 && jsConfirm('<%= Resources.demo.MSG_DELETE %>')) {
                    var item = $find("<%= datalist.ClientID %>").get_masterTableView().get_dataItems()[rowIndex];
                    var headerID = item.getDataKeyValue("HeaderID");
                    var userID = "<%= Session.User.ID %>"
                    patseer.web.webservices.SearchHistoryService.RemoveSearchHeader(userID, headerID, removeSearchHeader_OnSuccessCallback, removeSearchHeader_OnErrorCallback, item);
                }

            }

            function removeSearchHeader_OnSuccessCallback(result, dataItem) {
                if (result == true) {
                    ShowMessage('<%= Resources.demo.MSG_SUCCESSFULLY %>');
                    var masterTable = $find("<%= datalist.ClientID %>").get_masterTableView().get_element();
                    $(dataItem.get_element()).remove();
                    currentRowIndex = -1;
                }
                else {
                   
                }
            }

            function gridSearchResult_RowMouseOver(sender, eventArgs) {
                gridSearchResultCurrentRowIndex = eventArgs.get_itemIndexHierarchical();
            }

            function removeSearchTermFromHeader() {
                var rowIndex = gridSearchResultCurrentRowIndex;
                if (rowIndex > -1 && jsConfirm('<%=  Resources.demo.MSG_DELETE %>')) {
                    var item = $find("<%= gridSearchResult.ClientID %>").get_masterTableView().get_dataItems()[rowIndex];
                    var searchTermID = item.getDataKeyValue("SearchTermID");
                    patseer.web.webservices.SearchHistoryService.RemoveSearchTermFromHeader(searchTermID,
                            removeSearchTermFromHeader_OnSuccessCallback, removeSearchTermFromHeader_OnErrorCallback, item);
                }

            }

            function removeSearchTermFromHeader_OnSuccessCallback(result, dataItem) {
                if (result == true) {
                    ShowMessage('<%= Resources.demo.MSG_SEARCH_SUCCESSFULLY %>');
                    var grid = $find("<%= gridSearchResult.ClientID %>");
                    var masterTable = grid.get_masterTableView().get_element();
                    $(dataItem.get_element()).remove();
                    gridSearchResultCurrentRowIndex = -1;
                }
                else {
                    ShowErrorMessage('<%= Resources.demo.MSG_SEARCH_FAILED %>');
                }
            }

            function removeSearchTermFromHeader_OnErrorCallback(result) {
                ShowErrorMessage('<%= Resources.demo.MSG_FAILED %>');
            }

        </script>
    </telerik:RadCodeBlock>


    .cs file code block

    page_load
     datalist.NeedDataSource += new GridNeedDataSourceEventHandler(datalist_NeedDataSource);
                datalist.UpdateCommand += new GridCommandEventHandler(datalist_UpdateCommand);

    void datalist_UpdateCommand(object source, GridCommandEventArgs e)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;
                GridEditManager editMan = editedItem.EditManager;
                string editorText = ((e.Item as GridEditableItem)["SearchHeader"].Controls[0] as TextBox).Text;
                string headerID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["HeaderID"].ToString();
                if (!string.IsNullOrWhiteSpace(editorText))
                {
                  // insert into database
                    if (result != default(int))
                    {
                       
                        return;
                    }
                }
              
                e.Canceled = true;
            }
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 21 Nov 2011 Link to this post

    Hello,

    Try the following code.

    CS:
    protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
      GridEditFormItem editItem = e.Item as GridEditFormItem;
      Hashtable newValues = new Hashtable();
      e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem);
      string id = newValues["Name"].ToString();
    }

    Also take a look into the following documentation for more.
    Updating Values Using InPlace and EditForms Modes

    Thanks,
    Princy.
  3. Ravi
    Ravi avatar
    2 posts
    Member since:
    Nov 2011

    Posted 21 Nov 2011 Link to this post

    Thanks for reply
    in debug mode cursor not came in this code

    protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
      GridEditFormItem editItem = e.Item as GridEditFormItem;
      Hashtable newValues = new Hashtable();
      e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editItem);
      string id = newValues["Name"].ToString();
    }

  4. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 21 Nov 2011 Link to this post

    Hello,
    protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
     String StrCmd = e.CommandName;
    //let me know which value you get in StrCmd.
    }


    Thanks,
    Jayesh Goyani
  5. Ravi
    Ravi avatar
    2 posts
    Member since:
    Nov 2011

    Posted 21 Nov 2011 Link to this post

    Hello,

    When clicking update command did't get RadGrid1_ItemCommand
Back to Top