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

[Solved] edit on double click (AJAX)

4 Answers 167 Views
Grid
This is a migrated thread and some comments may be shown as answers.
regis
Top achievements
Rank 1
regis asked on 15 May 2009, 03:13 PM
Hi everyone,

I am trying to implement the feature of editing a row in radgrid on doubleclick event.
Everything works fine if i use gridboundcolumns and automatic update.

My problem is when there is a templatecolumn like this
<telerik:RadGrid ID="GridComment" runat="server" DataSourceID = "SqlDataSource1"   
            AutoGenerateColumns="False" AllowAutomaticUpdates ="true" OnItemUpdated="GridComment_ItemUpdated" 
            OnDataBound="GridComment_DataBound" ShowStatusBar="True" ShowFooter ="true">  
        <MasterTableView EditMode ="InPlace" >  
            <Columns>  
                <telerik:GridBoundColumn HeaderText = "Client Sample ID" DataField = "description" ReadOnly="true"/>  
                <telerik:GridBoundColumn HeaderText = "ID" DataField = "sampleid" ReadOnly ="true" ForceExtractValue ="InEditMode"  />  
                <telerik:GridBoundColumn Visible ="false" DataField= "error_id" UniqueName="error_id" ReadOnly ="true" ForceExtractValue ="InEditMode"/>   
                <telerik:GridBoundColumn HeaderText = "SIR" DataField = "error_type" ReadOnly="true"/>  
                <telerik:GridTemplateColumn HeaderText = "Comment" UniqueName="comments">  
                    <EditItemTemplate>  
                        <telerik:RadTextBox ID="EditTxtComment" runat="server" Text='<%# Bind("comments")%>' TextMode="MultiLine">  
                        </telerik:RadTextBox>  
                    </EditItemTemplate>  
                    <ItemTemplate>  
                        <telerik:RadTextBox ID="TxtComment" runat="server" Text='<%# Eval("comments")%>' TextMode="MultiLine" ReadOnly="true" >  
                        </telerik:RadTextBox>     
                    </ItemTemplate>  
                </telerik:GridTemplateColumn>  
                  
            </Columns>  
        </MasterTableView>  
        <ClientSettings>  
                <ClientEvents OnRowClick="RowClick" OnRowDblClick="RowDblClick" 
                    OnGridCreated="GridCreated" OnCommand="GridCommand" />  
            </ClientSettings>  
 
        </telerik:RadGrid> 


when i double click on the "comment row" the edit form is correctly used but I can't save my change.

When i debug the code i notice that on the click event:
function RowClick(sender, eventArgs) {  
 
                if (editedRow && hasChanges) {  
 
                    hasChanges = false;  
                    if (confirm("Update changes?")) {  
 
                        $find("<%= GridComment.MasterTableView.ClientID %>").updateItem(editedRow);  
                    }  
                }  
            } 
the variable hasChanges is false even if modification where made.
Debuging again i found that during this event:
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;  
                }  
 
                dropdowns = gridElement.getElementsByTagName("select");  
                for (var i = 0; i < dropdowns.length; i++) {  
                      
                    dropdowns[i].onchange = TrackChanges;  
                      
                }  
 
                setTimeout(function() { if (elementsToUse[0]) elementsToUse[0].focus(); }, 100);  
            } 
my edittemplateitem was not added to "inputs" and thus don't receive the "onchange=TrackChanges".

I think inputs = gridElement.getElementsByTagName("input"); "
doesn't collect my edittemplateitem because it's hidden but i am not sure at all.

Any advice?

thank you

4 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 18 May 2009, 11:45 AM
Hi regis,

I could not reproduce this problem as evidenced by the sample I am sending you.

Please, take a look at it and see if it helps.

Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
regis
Top achievements
Rank 1
answered on 21 May 2009, 02:46 PM
Hi,
And thank you for you answer.

I manage to make my project works but not in the way i really would like, and in the same time i manage to make you project to fail.

If you set the textmode property of the edititemtemplate to "multiline":
                        <telerik:GridTemplateColumn HeaderText="UnitPrice">  
                            <ItemTemplate> 
                                  
                                <asp:Label ID="unitLabel" runat="server" Text='<%#Eval("UnitPrice") %>'></asp:Label> 
                            </ItemTemplate> 
                            <EditItemTemplate> 
                                <telerik:RadTextBox ID="textBox" runat="server" Text='<%#Bind("UnitPrice") %>' TextMode="MultiLine">  
                                </telerik:RadTextBox> 
                            </EditItemTemplate> 
                        </telerik:GridTemplateColumn> 

i can't save (the onclick event is not firing because of hasChanges to false)

Is there a particular reason to that. What should i do to have a multiline textbox?

Thank you

Regis
0
Accepted
Tsvetoslav
Telerik team
answered on 25 May 2009, 07:32 AM
Hello regis,

RadTextBox with the TextMode property set to MultiLine is rendered as a textarea html element, therefore you need to attach the TrackChanges event handler to this type of html elements of the grid.

Please, take a look at the modified version of the sample.

Kind regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
regis
Top achievements
Rank 1
answered on 01 Jun 2009, 02:40 PM
Hi,

Thank you for you answer and sorry for the delay.

Your solution works prefectly. Thank you so much.
Tags
Grid
Asked by
regis
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
regis
Top achievements
Rank 1
Share this question
or