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

OnRowDblClick does not set in EditMode

2 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
July
Top achievements
Rank 2
July asked on 19 Oct 2011, 04:52 PM
OnRowDblClick doesnt fire Radgrid in Edit Mode.
I read a lot of post but i didnt found the solution.

I attach image of grid!
This is My code:

File.Cs
public partial class Communities : System.Web.UI.Page
  {

    #region Properties&Variables

    private Organization _organization;
    private string _culture;
    private ResourceManager _recources;

    #endregion

    #region Events

   
    protected void Page_Load(object sender, EventArgs e)
    {
        GetInfo();

        if (!Page.IsPostBack)
        {
            LoadSettings();
        }
    }

    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        LoadData();
    }
      
    protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
    {
      var communityId = ((GridDataItem) e.Item).GetDataKeyValue("Id").ToString();

      _organization = new Organization
      {
        Community = new Community { Id = Convert.ToInt16(communityId) }
      };


      if (_organization.CommunityHasUser())
      {
        RadWindowManager1.RadConfirm("The Community has associated users. <br> If you delete Community, then users associated will deleted too. <br> Delete this Community?", null, 330, 100, null, "Community and Users");

      }

      _organization.RemoveCommunity();
    }

    protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
    {
        if (!Page.IsValid) return;

        GridEditableItem item = e.Item as GridEditableItem;
        if (item != null)
        {
           
            Hashtable values = new Hashtable();
            item.ExtractValues(values);

            _organization = new Organization();

            _organization.Community = new Community
            {
               
                Name = values["Name"] == null ? null : values["Name"].ToString(),
                Description = values["Description"] == null ? null : values["Description"].ToString()

            };
        }
        _organization.CreateCommunity();

    }

    protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
    {
      if (!Page.IsValid) return;

      GridEditableItem item = e.Item as GridEditableItem;
      if (item != null)
      {
        var communityId = item.GetDataKeyValue("Id");
        Hashtable values = new Hashtable();
        item.ExtractValues(values);

          _organization = new Organization
                              {
                                  Community = new Community
                                                  {
                                                      Id = Convert.ToInt16(communityId),
                                                      Name = values["Name"] == null ? null : values["Name"].ToString(),
                                                      Description =
                                                          values["Description"] == null
                                                              ? null
                                                              : values["Description"].ToString()
                                                  }
                              };
      }
      _organization.UpdateCommunity();
    }

    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {

      this.RadGrid1.MasterTableView.GetColumnSafe("RowIndicator").Display = false;

    }

    protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        String id = item.GetDataKeyValue("Id").ToString();

        if (e.Exception != null)
        {
            e.KeepInEditMode = true;
            e.ExceptionHandled = true;
           
        }
      
    }

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
      if (_recources == null || _culture == null) GetInfo();

      if (e.Item is GridDataItem )
      {
          if (e.EventInfo is GridItemCreated) return;
          if (e.Item.ItemIndex < 0) return;

          ImageButton editLink = (ImageButton)e.Item.FindControl("EditLink");
          editLink.AlternateText = _recources.GetString(editLink.ID, new CultureInfo(_culture));
          editLink.Attributes["href"] = "#";

          editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"], e.Item.ItemIndex);
      }

        GridCommandItem item = e.Item as GridCommandItem;
       if(item != null)
       {
           Label lblQuickAdd = ((Label)item.FindControl("lblQuickAdd"));
           lblQuickAdd.Text = _recources.GetString(lblQuickAdd.ID, new CultureInfo(_culture));

           Label lblFullAdd = ((Label)item.FindControl("lblFullAdd"));
           lblFullAdd.Text = _recources.GetString(lblFullAdd.ID, new CultureInfo(_culture));
       }
       


        /*validations*/

        if (e.Item is GridEditableItem && e.Item.IsInEditMode)
        {
            for (int i = 2; i < RadGrid1.MasterTableView.Columns.Count; i++)
            {
                if (RadGrid1.MasterTableView.Columns[i].IsEditable && RadGrid1.MasterTableView.Columns[i].UniqueName.ToLower() == "name" )
                { AddRequiredValidator(RadGrid1.MasterTableView.Columns[i].UniqueName, e);
                AddCustomValidator(RadGrid1.MasterTableView.Columns[i].UniqueName, e);
                }
              
            }

        }
    }

    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
      if (e.Argument == "Rebind")
      {
        RadGrid1.MasterTableView.SortExpressions.Clear();
        RadGrid1.MasterTableView.GroupByExpressions.Clear();
        RadGrid1.Rebind();
      }
      else if (e.Argument == "RebindAndNavigate")
      {
        RadGrid1.MasterTableView.SortExpressions.Clear();
        RadGrid1.MasterTableView.GroupByExpressions.Clear();
        RadGrid1.MasterTableView.CurrentPageIndex = RadGrid1.MasterTableView.PageCount - 1;
        RadGrid1.Rebind();
      }
    }

    protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.EditCommandName)
        {
            Session["ID"] = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"];
        }

        if (e.CommandName == RadGrid.InitInsertCommandName) //"Quick add new" button clicked
        {
          
            GridTemplateColumn fulledit = (GridTemplateColumn)RadGrid1.MasterTableView.GetColumn("TemplateEditColumn");
            fulledit.Visible = false;
        }
        else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
        {
            e.Canceled = true;
        }
        else
        {
          
            GridTemplateColumn fulledit = (GridTemplateColumn)RadGrid1.MasterTableView.GetColumn("TemplateEditColumn");
            if (!fulledit.Visible)
                fulledit.Visible = true;
            
        }
    }
    #endregion

    #region Methods


    private void AddCustomValidator(string colName, GridItemEventArgs e)
    {
        GridEditableItem itemEditable = e.Item as GridEditableItem;

        if (itemEditable != null)
        {
            GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)itemEditable.EditManager.GetColumnEditor(colName);
            TableCell cell = (TableCell)editor.TextBoxControl.Parent;

            CustomValidator validator = new CustomValidator();
            editor.TextBoxControl.ID = colName;
            validator.ControlToValidate = editor.TextBoxControl.ID;
            validator.CssClass = "validator";
            validator.Display = ValidatorDisplay.Dynamic;
            validator.ErrorMessage = _recources.GetString("cv" + colName, new CultureInfo(_culture));
            validator.ServerValidate += cvName_ServerValidate;
            cell.Controls.Add(validator);
        }
    }

    protected void cvName_ServerValidate(object sender, ServerValidateEventArgs e)
    {
        _organization = new Organization();
        e.IsValid = !_organization.ExistCommunityName(e.Value.ToString(), GetId());
    }

    private int GetId()
    {
        return Convert.ToInt16(Session["ID"] ?? 0);
    }

    private void AddRequiredValidator(string colName, GridItemEventArgs e)
    {
        GridEditableItem itemEditable = e.Item as GridEditableItem;
        if (itemEditable == null) return;

        GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)itemEditable.EditManager.GetColumnEditor(colName);
        TableCell cell = (TableCell)editor.TextBoxControl.Parent;

        RequiredFieldValidator validator = new RequiredFieldValidator();
        editor.TextBoxControl.ID = colName;
        validator.ControlToValidate = editor.TextBoxControl.ID;
        validator.CssClass = "validator";
        validator.Display = ValidatorDisplay.Dynamic;
        validator.ErrorMessage = "*";
        cell.Controls.Add(validator);
    }

    private void SetColumnHeader(string name)
    {
      RadGrid1.MasterTableView.GetColumnSafe(name).HeaderText = _recources.GetString( "lbl" + name , new CultureInfo(_culture));
    }

    private void LoadSettings()
    {
      var type = Request.QueryString["Type"];
      if (string.IsNullOrEmpty(type)) type = "List";

      SetSettings("lblTitileList");

      for (int i =2; i < RadGrid1.MasterTableView.Columns.Count; i++ )
      {
        if (RadGrid1.MasterTableView.Columns[i].IsEditable && RadGrid1.MasterTableView.Columns[i].UniqueName.ToLower() !="id")
          SetColumnHeader(RadGrid1.MasterTableView.Columns[i].UniqueName);
      }


     
         
      GridButtonColumn btndelete = (GridButtonColumn) RadGrid1.Columns.FindByUniqueName("btnDelete");
      btndelete.ConfirmText = _recources.GetString("confirmText", new CultureInfo(_culture));
      btndelete.ConfirmTitle = _recources.GetString("confirmTitle", new CultureInfo(_culture));

      GridSettings();

    
      switch (type)
      {
        case "New":
        
         Page page = HttpContext.Current.CurrentHandler as Page;
 
         if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
         {
           const string prueba = "javascript: window.radopen('CommunityForm.aspx', ''UserListDialog');";
           System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "scriptpop", prueba, true);
         }
          break;
      }
    
    }

    private void GridSettings()
    {
      RadGrid1.ClientSettings.EnablePostBackOnRowClick = true;
      RadGrid1.ClientSettings.AllowColumnsReorder = true;
      RadGrid1.ClientSettings.ReorderColumnsOnClient = true;
      RadGrid1.ClientSettings.ColumnsReorderMethod = GridClientSettings.GridColumnsReorderMethod.Swap;
      RadGrid1.ClientSettings.AllowColumnHide = true;
      RadGrid1.ClientSettings.Resizing.AllowColumnResize = false;
      RadGrid1.ClientSettings.Resizing.AllowResizeToFit = true;
      RadGrid1.ClientSettings.Resizing.EnableRealTimeResize = true;
      RadGrid1.ClientSettings.Resizing.ResizeGridOnColumnResize = true;
      RadGrid1.ClientSettings.Resizing.AllowColumnResize = true;
      RadGrid1.ClientSettings.Resizing.ClipCellContentOnResize = true;
      RadGrid1.Culture = new CultureInfo(_culture);
    }

    private void SetSettings(string resx)
    {
      if (resx != null) lblTitle.Text = _recources.GetString(resx, new CultureInfo(_culture));
    }

    private void LoadData()
    {
      _organization = new Organization();

      try
      {
        RadGrid1.DataSource = _organization.GetCommunities();
      }
      catch (Exception ex)
      {
        WriterLog.WriterinlogFil(ex);
        throw new Exception(ex.ToString());
      }
     
    }
    
    private void GetInfo()
    {
      _culture = App.CurrentCulture();
       _recources = App.GetAdminResources("Communities");
    }
   


     #endregion
  }

File.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/UI/Doculex.Master" AutoEventWireup="true"
    CodeBehind="Communities.aspx.cs" Inherits="WebSearch.UI.Admin.Communities" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
     
           

       
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server" >

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


            function ShowEditForm(id, rowIndex) {
                var grid = $find("<%= RadGrid1.ClientID %>");

                var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
                grid.get_masterTableView().selectItem(rowControl, true);

                var oWindow = window.radopen("CommunityForm.aspx?ID=" + id, "UserListDialog");
                oWindow.SetTitle("Editing Community");

                return false;
            }

            function ShowInsertForm() {
                var oWindow = window.radopen("CommunityForm.aspx", "UserListDialog");
                oWindow.SetTitle("New Community - Full Add");
                return false;
            }


            function ShowQuickInsertForm() {
                var oWindow = window.radopen("CommunityForm.aspx?T=Q", "UserListDialog");
                oWindow.SetTitle("New Community - Quick Add");
                return false;
            }


            function refreshGrid(arg) {
                if (!arg) {
                    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
                }
                else {
                    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");
                }
            }
            function RowDblClick(sender, eventArgs) {
           
                sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
               

            }
           
            
              
        </script>

    </telerik:RadCodeBlock>   
 <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"  >
             <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        <telerik:AjaxUpdatedControl ControlID="RadWindowManager1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>                            
                </AjaxSettings>
            </telerik:RadAjaxManager>
    <div class="headerPage">
        <asp:Label ID="lblTitle" runat="server"></asp:Label>
    </div>
    <div class="containerSub">
        
            <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
                AllowPaging="True" AllowSorting="True" OnDeleteCommand="RadGrid1_DeleteCommand"
                 AllowFilteringByColumn="True" OnUpdateCommand="RadGrid1_UpdateCommand" OnInsertCommand="RadGrid1_InsertCommand"
                Width="99.8%" PageSize="10" Height="500px" AutoGenerateColumns="False" CellSpacing="0" OnItemCommand="RadGrid1_ItemCommand"
                          OnItemUpdated="RadGrid1_ItemUpdated"
                 GridLines="None" OnPreRender="RadGrid1_PreRender" OnItemCreated="RadGrid1_ItemCreated">

                  <MasterTableView DataKeyNames="Id" CommandItemDisplay="Top"
                    EditMode="InPlace" TableLayout="Fixed" >
                    
                    <Columns>
                         <telerik:GridTemplateColumn UniqueName="TemplateEditColumn"  HeaderStyle-Width="3%"  AllowFiltering="false">
                        <ItemTemplate>
                            <asp:ImageButton ID="EditLink" runat="server"   ImageUrl="~/UI/Images/pencil.png" ></asp:ImageButton>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                     <telerik:GridEditCommandColumn HeaderStyle-Width="3%" UniqueName="EditCommandColumn"  ButtonType="ImageButton" EditImageUrl="../Images/grid_edit.png">
                       
                    </telerik:GridEditCommandColumn>
                        <telerik:GridButtonColumn UniqueName="btnDelete" ConfirmDialogType="RadWindow"
                            ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="100px" ConfirmDialogWidth="300px"
                            HeaderStyle-Width="3%" />
                        <telerik:GridTemplateColumn DataField="Id" HeaderText="Id" UniqueName="Id" Visible="false">
                            <InsertItemTemplate>
                                <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Bind("Id") %>' Width="150px"
                                    ReadOnly="true" Enabled="false" />
                            </InsertItemTemplate>
                            <EditItemTemplate>

                                <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# Eval("Id") %>' ReadOnly="true"
                                    Width="150px" />
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="Name" UniqueName="Name" ColumnEditorID="editorName" />
                        <telerik:GridBoundColumn DataField="Description" UniqueName="Description" ColumnEditorID="editorDescription"  />                       
                    </Columns>
                   
                      <CommandItemTemplate>
                        <div style="width: 100%">
                            <div style="width: 10%; margin-left: 12px; float: left">
                             <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" ><asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/UI/Images/add.png" /> <asp:Label ID="lblQuickAdd" runat="server" /></asp:LinkButton>&nbsp;&nbsp; </div><div style="width: 10%; float: left">
                                <a href="#" onclick="return ShowInsertForm();">
                                    <asp:ImageButton ID="imgAddFull" runat="server" ImageUrl="~/UI/Images/add.png" />
                                    <asp:Label ID="lblFullAdd" runat="server" />
                                </a>
                            </div>
                        </div>
                    </CommandItemTemplate>
                         
                
                 
                         </MasterTableView>    
                                 <ClientSettings >
                        <ClientEvents OnRowDblClick="RowDblClick"   />
                    </ClientSettings>                                           
                             <PagerStyle Mode="NumericPages" />
            </telerik:RadGrid>
          <telerik:GridTextBoxColumnEditor ID="editorName" runat="server" TextBoxStyle-Width="200px" />             
            <telerik:GridTextBoxColumnEditor ID="editorDescription" runat="server" TextBoxStyle-Width="200px" />  
         <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
            <Windows>
                <telerik:RadWindow ID="UserListDialog" runat="server"  Height="600px"
                    Width="850px" Left="15%" ReloadOnShow="true" ShowContentDuringLoad="false"  
                    Modal="true" VisibleStatusbar="True" Behaviors="Close"   />


            </Windows>
        </telerik:RadWindowManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
    </div>
</asp:Content>


I use master/details

I need fix this urgent!

Thanks

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Oct 2011, 06:11 PM
Hello,

Grid / Edit on Double-click

try with below function


function RowDblClick(sender, eventArgs)
         {
             editedRow = eventArgs.get_itemIndexHierarchical();
             $find("<%= RadGrid1.ClientID %>").get_masterTableView().editItem(editedRow);
         }



 <ClientSettings>
                <ClientEvents OnRowDblClick="RowDblClick"/>
            </ClientSettings>



Note : if you still have issue then set AllowAutomaticUpdates="True"


Thanks.
Jayesh Goyani
0
July
Top achievements
Rank 2
answered on 19 Oct 2011, 09:01 PM
Doesn't work :-(

Other ideas?? :-(
Tags
Grid
Asked by
July
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
July
Top achievements
Rank 2
Share this question
or