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

[Solved] editItem() causes callback?

2 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Charles Forsyth
Top achievements
Rank 2
Charles Forsyth asked on 12 Jun 2008, 01:08 AM

I'm sure I am just missing some information here.

When a radGrid for Ajax goes into edit mode it shouldn't submit the form right?

I don't want the radGrid to refresh when it goes into edit mode.

The aspx and code behind is rather large. I'll try to cut it down to just the relevant pieces for you. The entire page is meant to mimik the behavior of the Windows File Explorer. What I'm trying to do now is put the grid into edit in place mode so the end user can edit the name of the folder or file prior to submitting to the server to do that action on the server. But like I said, when I put it into edit mode, it refreshes and returns the "empty data" template, not the edit mode template.


Here's the JavaScript code I use to put the grid into edit mode...

function onGridRowClick(sender, args) {  
    var index = args.get_itemIndexHierarchical();  
    // Put item into edit mode if clicked after selected (slow double-click)  
    if (currentSelectedGridRowIndex != null) {  
        if (index == currentSelectedGridRowIndex) {  
            var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();  
            masterTable.editItem(index);  
        }  
    }  
    currentSelectedGridRowIndex = index;  

Note that the currentSelectedGridRowIndex variable is global.

Anyhow, this works as I want, except then the masterTable.editItem(index); is called the form is submitted. (callback when ajax enabled) and my radGrid loses it's data.

Here's the markup for the radGrid...

<telerik:RadGrid ID="RadGrid1" runat="server"    
    AutoGenerateColumns="False" 
    GridLines="None" 
    Skin="Office2007" 
    Width="100%" 
    BorderWidth="0px">  
    <MasterTableView   
        clientDataKeyNames="Path,Name,Type" 
        EditMode="InPlace">  
        <Columns> 
            <telerik:GridTemplateColumn HeaderText="Name" UniqueName="Name">  
                <ItemTemplate> 
                    <asp:Image ID="icon" runat="server" ImageAlign="absmiddle" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "Icon") %>' AlternateText="icon" BorderWidth="0" /> 
                    <asp:Label ID="name" runat="server" style="cursor:default;" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label> 
                </ItemTemplate> 
                <ItemStyle BorderStyle="None" Wrap="False" /> 
                <HeaderStyle Width="300px" /> 
                <EditItemTemplate> 
                    <asp:TextBox ID="TextBox_NewName" runat="server"></asp:TextBox> 
                </EditItemTemplate> 
            </telerik:GridTemplateColumn> 
            <telerik:GridTemplateColumn HeaderText="Size" UniqueName="Size">  
                <ItemTemplate> 
                    <asp:Label ID="size" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Size") %>'></asp:Label> 
                </ItemTemplate> 
                <ItemStyle BorderStyle="None" Width="100px" Wrap="False" /> 
                <HeaderStyle Width="100px" /> 
                <EditItemTemplate> 
                    <asp:Label ID="size" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Size") %>'></asp:Label> 
                </EditItemTemplate> 
            </telerik:GridTemplateColumn> 
            <telerik:GridTemplateColumn HeaderText="Modified" UniqueName="Modified">  
                <ItemTemplate> 
                    <asp:Label ID="modified" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Modified") %>'></asp:Label> 
                </ItemTemplate> 
                <ItemStyle BorderStyle="None" Width="230px" Wrap="False" /> 
                <HeaderStyle Width="230px" /> 
                <EditItemTemplate> 
                    <asp:Label ID="modified" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Modified") %>'></asp:Label> 
                </EditItemTemplate> 
            </telerik:GridTemplateColumn> 
        </Columns> 
          
        <NoRecordsTemplate> 
            No Files or Folders.  
        </NoRecordsTemplate> 
        <ExpandCollapseColumn Visible="False" Resizable="False">  
            <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
        <RowIndicatorColumn Visible="False">  
            <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
        <EditFormSettings> 
            <PopUpSettings ScrollBars="None" /> 
        </EditFormSettings> 
    </MasterTableView> 
    <ItemStyle BorderStyle="None" /> 
    <ClientSettings> 
        <Resizing AllowColumnResize="True" /> 
        <Selecting AllowRowSelect="True" /> 
        <ClientEvents OnRowClick="onGridRowClick" OnRowContextMenu="onGridRowContextMenu" OnRowDblClick="onGridRowDoubleClick" OnRowSelecting="onGridRowSelecting" /> 
    </ClientSettings> 
</telerik:RadGrid> 

These are the only two server-side event handlers...

    Private Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
        If RadTreeView1.SelectedNode IsNot Nothing Then 
            LoadGrid(RadTreeView1.SelectedNode.Value)  
        Else 
            LoadGrid(selectedPath)  
        End If 
    End Sub 
 
    Private Sub RadGrid1_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated  
        If TypeOf e.Item Is GridDataItem Then 
            Dim dataItem As GridDataItem = TryCast(e.Item, GridDataItem)  
            e.Item.Attributes("onmousedown") = String.Format("onGridMouseDown(event, this,{0})", dataItem.DataSetIndex)  
        End If 
    End Sub 

2 Answers, 1 is accepted

Sort by
0
Charles Forsyth
Top achievements
Rank 2
answered on 12 Jun 2008, 01:38 AM
Ultimately what I want to happen is the same behavior that happens when you edit an item in the radTreeView.

I want the client to be able to edit a name (folder or file) then after editing is completed submit the form and attempt to rename the file or folder on the server.

I'd rather not have to submit the form back to the server just to go into edit mode if that's at all possible. (like you can do with the radTreeView)

Any ideas or help would be appreciated.
0
Sebastian
Telerik team
answered on 16 Jun 2008, 12:10 PM
Hello Charles,

Thank you for the suggestion. I will forward it to our RadGrid development department for further consideration. If this appears to be a common request and a feasible enhancement, you may see it included in a future version of the product.

In the meantime you may either implement editing on double-click as illustrated in this online demo of the product:

http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/EditOnDblClick/DefaultCS.aspx

or stand by for the next release of RadGrid for ASP.NET AJAX (part of Q2 2008, expected at the end of July) where we will introduce client-binding/editing through web services. If you are interested to learn more about the second utility, review the series of blog posts of my colleague Vlad on telerik.com:

http://blogs.telerik.com/VladimirEnchev/Posts.aspx

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Charles Forsyth
Top achievements
Rank 2
Answers by
Charles Forsyth
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or