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

[Solved] Radgrid with inline update custom template: getting data from custom controls

3 Answers 256 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jean-Marc Windholz
Top achievements
Rank 1
Jean-Marc Windholz asked on 25 Nov 2009, 11:52 AM

Hi everybody,

my radgrid shows records from my DB, using inline editing with custom template such as a textbox "tbNT" and a checkbox "cbA".

 

I catch the RadGrid1_UpdateCommand event for update data on my DB.

I have found no way to get values from the "tbNT" textBox and "cbA" checkBox in the event function.

I would also like to know how to get the record (line in radgrid) that need updated data.

 

I have searched and tried quite a few methods from radgrid examples with no luck.

 

Thank you very much

 Here is aspx code (part of):

<telerik:RadGrid ID="RadGrid1" runat="server" Width="98%"   
                       AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource1"             
CellPadding="1" Height="700px" BorderStyle="Solid" GridLines="Both"  
      AutoGenerateColumns="False"                        AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True"
 
<MasterTableView EditFormSettings-EditFormType="Template" DataSourceID="SqlDataSource1" 
DataKeyNames="ArtID" Width="100%"
 
      <Columns> 
         <telerik:GridBoundColumn DataField="RssID" HeaderText="RssID" SortExpression="RssID" HeaderStyle-Width="50" UniqueName="RssID" DataType="System.Int32"
 
<HeaderStyle Width="50px"></HeaderStyle> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Title" HeaderText="Titolo" 
                                    SortExpression="Title" 
UniqueName="Title"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="PubDate" HeaderText="Data Pubblicazione" HeaderStyle-Width="100" 
                                    SortExpression="PubDate" 
UniqueName="PubDate" DataType="System.DateTime"<HeaderStyle Width="100px"></HeaderStyle> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="InsDate" DataType="System.DateTime"  HeaderStyle-Width="100" 
                                    HeaderText="Data Inserimento" 
SortExpression="InsDate" UniqueName="InsDate"<HeaderStyle Width="100px"></HeaderStyle> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="NewTitle" HeaderText="Titolo Sito" HeaderStyle-Width="200" 
                                    SortExpression="NewTitle" 
UniqueName="NewTitle"
<HeaderStyle Width="200px"></HeaderStyle> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridCheckBoxColumn DataField="Active" DataType="System.Boolean HeaderStyle-Width="50
                                    HeaderText="Attivo" 
SortExpression="Active" UniqueName="Active"<HeaderStyle Width="50px"></HeaderStyle> 
                                </telerik:GridCheckBoxColumn> 
                                <telerik:GridBoundColumn DataField="ActDate" HeaderText="ActDate"  HeaderStyle-Width="100" 
                                    SortExpression="Data Attivazione" 
UniqueName="ActDate" DataType="System.DateTime"<HeaderStyle Width="100px"></HeaderStyle> 
                                </telerik:GridBoundColumn> 
                            </Columns> 
 
                            <EditFormSettings EditFormType="Template"
                                <FormTemplate> 
                                    <table id="Table5" cellspacing="2" 
cellpadding="1" width="100%" border="0" rules="none" 
                                            style="border-collapse: 
collapse; background: white;"> 
                                        <tr> 
                                            <td> 
                                                Nuovo Titolo: 
<asp:TextBox ID="tbNT" runat="server" Text='<%# Bind( "NewTitle") %>' 
Width="400" /> 
                                                &nbsp;&nbsp; 
                                                Attivo: <asp:CheckBox ID="cbA" runat="server" Text="" Checked='<%# Bind( "Active") %>' /> 
                                                &nbsp;&nbsp; 
                                                
                                                <asp:Button ID="btnUpdate" text="Aggiorna" runat="server" CommandName="Update"
                                                </asp:Button> 
                                                &nbsp; 
 
                                                <asp:Button ID="btnCancel" Text="Annulla" runat="server" CausesValidation="False" 
CommandName="Cancel"
                                                </asp:Button> 
                                            </td> 
                                        </tr> 
                                    </table> 
                                </FormTemplate> 
                            </EditFormSettings> 
 
                        </MasterTableView> 
 
                        <ClientSettings> 
                            <Scrolling AllowScroll="True" 
UseStaticHeaders="True" /> 
                        </ClientSettings> 
                    </telerik:RadGrid> 
 
 
 
 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Nov 2009, 12:27 PM
Hello Jean,

You can use the following code to access the edit form item controls in UpdateCommand.

CS:
 
 protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
        GridEditFormItem editItem = (GridEditFormItem)e.Item; 
        string strtxt1 = ((TextBox)editItem.FindControl("tbNT")).Text; 
        string strtxt2 = ((CheckBox)editItem.FindControl("cbA")).Checked.ToString(); 
    }  

-Shinu.
0
Jean-Marc Windholz
Top achievements
Rank 1
answered on 25 Nov 2009, 02:28 PM
Shinu, thank you for your (very fast) response. It work perfectly.

But what the code to get the current edited grid's row???

Thank you very much for your support.

Best regards
Jean-Marc
0
Nikolay Rusev
Telerik team
answered on 27 Nov 2009, 07:29 AM
Hello Jean-Marc,

GridEditFormItem editItem = (GridEditFormItem)e.Item; is your current edit item.

All the best,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Jean-Marc Windholz
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jean-Marc Windholz
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or