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

Automatic operations and custom template edit form

4 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aleksandar
Top achievements
Rank 1
Aleksandar asked on 30 Oct 2008, 12:05 PM
To test automatic updates/inserts/deletes, I am using your sample app at: http://www.telerik.com/community/code-library/submission/b311D-kkmhe.aspx
It works fine for AutoGenerated edit form, but not for template form. To reproduce the problem, just paste the following code after closing columns tag (</COLUMNS>):

<EditFormSettings CaptionDataField="Edit contact:" ColumnNumber="2" EditFormType="Template" > 
                <FormTemplate> 
                <table id="ContactsMiddle" runat="server" style="width:100%; border:none 0px #ffffff; color:#9EB6CE; text-align:left;">  
                                    <tr> 
                        <td style="width:100px; padding-left:10px" >Last Name:</td> 
                        <td style="width:250px;"><asp:TextBox runat="server" EnableViewState="true" Width="70%" ID="inpContactName" Text='<%#Bind("LastName")%>'></asp:TextBox></td>  
                        <td style="width:100px; padding-left:10px" >First Name:</td> 
                        <td style="width:250px;"><asp:TextBox runat="server" EnableViewState="true" Width="70%" ID="inpContactHomePhone" Text='<%#Bind("FirstName")%>'></asp:TextBox></td>  
                    </tr> 
                    <tr> 
                        <td style="width:100px; padding-left:10px" >Title:</td> 
                        <td style="width:250px;"><asp:TextBox runat="server" EnableViewState="true" Width="70%" ID="inpContactEmail" Text='<%#Bind("Title")%>'></asp:TextBox></td>  
                        <td style="width:100px; padding-left:10px" >Address:</td> 
                        <td style="width:250px;"><asp:TextBox runat="server" EnableViewState="true" Width="70%" ID="inpContactCellPhone" Text='<%#Bind("Address")%>'></asp:TextBox></td>  
                    </tr> 
                    <tr> 
                        <td style="width:100px; padding-left:10px" >Date:</td> 
                        <td style="width:250px;"><asp:TextBox runat="server" EnableViewState="true" Width="70%" ID="TextBox1" Text='<%#Bind("HireDate")%>'></asp:TextBox></td>  
                        <td style="width:350px; padding-left:10px" colspan="2" > 
                            <asp:LinkButton CssClass="lnkSubmit" ID="btnOK" runat="server" CommandName="Update">OK</asp:LinkButton> 
                            <asp:LinkButton CssClass="lnkSubmit" ID="btnCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton> 
                        </td> 
                    </tr> 
 
                </table> 
 
                </FormTemplate> 
                  
                </EditFormSettings> 

The returned error is:

You have specified that your update command compares all values on SqlDataSource 'SqlDataSource1', but the dictionary passed in for oldValues is empty.  Pass in a valid dictionary for update or change your mode to OverwriteChanges.

I see only one example with edit form template on your web site, and that one is using non-standard data source and is visualy very difficult to follow. Not to mention dirty code with ? instead of parameter names and non-maximisable code window. Link: http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/DataEditing/TemplateFormUpdate/DefaultCS.aspx
Please let me know how to use custom template form for automatic operations.

Regards,
Alex

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 31 Oct 2008, 01:37 PM
Hello Aleksandar,

Please test the example I attached to this thread. It is a simplified version of our online demo.

I hope this helps.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mario Turcotte
Top achievements
Rank 1
answered on 18 Feb 2011, 08:27 PM
I'm having a similar layout from the OP at the exception that where you have "First Name", "Last Name" etc.. I'm having labels. I need to access the labels to set the text based on the current user culture.

I'm using ASP.NET AJAX Q3 2010

Edit mode set to: RadGridPersonel.MasterTableView.EditMode = GridEditMode.PopUp;

Here is my edit/insert template;
<EditFormSettings InsertCaption="Add new record" CaptionFormatString="Edit Personnel: {0}" CaptionDataField="FIRST_NAME" EditFormType="Template">
      
    <FormTemplate>
        <table id="personnelFormTable" cellspacing="1" cellpadding="1" width="400" border="0">
            <tr>
                <td colspan="2">
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="editForm" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblFirstName" runat="server" Text="First name"></asp:Label>:
                </td>
                <td>
                    <telerik:RadTextBox ID="rtbFirstName" runat="server" Text='<%# Bind("FIRST_NAME") %>' MaxLength="50">
                    </telerik:RadTextBox>
                    <asp:RequiredFieldValidator ID="rfvFirstName" runat="server" ErrorMessage="Fisrt name is mandatory" ToolTip="Fisrt name is mandatory" ControlToValidate="rtbFirstName" ValidationGroup="editForm">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblLastName" runat="server" Text="Last name"></asp:Label>:
                </td>
                <td>
                    <telerik:RadTextBox ID="rtbLastName" runat="server" Text='<%# Bind("LAST_NAME") %>' MaxLength="50">
                    </telerik:RadTextBox>
                    <asp:RequiredFieldValidator ID="rfvLastName" runat="server" ErrorMessage="Last name is mandatory" ToolTip="Last name is mandatory" ControlToValidate="rtbLastName" ValidationGroup="editForm">*</asp:RequiredFieldValidator>
                </td>
            </tr>
             <tr>
                <td>
                    <asp:Label ID="lblLocation" runat="server" Text="Location"></asp:Label>:
                </td>
                <td>
                     <telerik:RadComboBox ID="rcbLocation" runat="server" AppendDataBoundItems="true" 
                        DataSourceID="odsLocation" DataTextField="Name" 
                        DataValueField="LOCATION_ID" SelectedValue='<%# Bind("LOCATION_ID") %>' onprerender="rcbLocation_PreRender">
                        <Items>
                            <telerik:RadComboBoxItem Text="" Value="" />
                        </Items>  
                    </telerik:RadComboBox>
                    <asp:RequiredFieldValidator ID="rfvLocation" runat="server" ErrorMessage="Location is mandatory" ToolTip="Location is mandatory" ControlToValidate="rcbLocation" ValidationGroup="editForm">*</asp:RequiredFieldValidator>
                </td>
            </tr>
        </table>
        <table style="width: 100%">
            <tr>
                <td align="right" colspan="2">
                    <asp:Button ID="btnSave" Text='<%# (Container is GridEditFormInsertItem) ? GetGlobalizedValue("Insert") : GetGlobalizedValue("Update") %>'
                        runat="server" 
                        CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' 
                        ValidationGroup="editForm" CausesValidation="true">
                    </asp:Button
                    <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                    </asp:Button>
                </td>
            </tr>
        </table>
     </FormTemplate>
</EditFormSettings>

From that template I need to set the text for lblFirstName, lblLastName, lblLocation, btnSave and btnCancel.

and here is what I have so far;
protected void RadGridPersonel_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.InitInsertCommandName )
    {
        (RadGridPersonnel.FindControl("lblFirstName") as Label).Text = Resources.RadGrid.Template.FirstName.ToString();
    }
}
RadGrid.Template is a resource file I created and which contains the FirstName etc keys.
However this fail.

What I'm doing wrong? Can someone help please!
0
Princy
Top achievements
Rank 1
answered on 21 Feb 2011, 06:01 AM
Hello Mario,

You can access the Label and set its text in ItemDataBound like below.

C#:
protected void RadGridPersonel_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
        {
            GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
            Label lb = (Label)insertItem.FindControl("lblFirstName");
            lb.Text = // your value
        }
    }

Thanks,
Princy.
0
Mario Turcotte
Top achievements
Rank 1
answered on 21 Feb 2011, 03:21 PM
Princy, thank you for your reply. I tried your approach which is similar to a few I did before and worked on other projects. However for that project it leaves the label blank. I have been given that application last week and I fount out that every grid use a base class to perform some routines. Nothing with text thought. I believe this add a round trip to the server and remove everything I can change dynamically from the templates. I've tried from ItemDataBound, ItemCreated and ItemCommand and none works.

When I go like this on the aspx page;

<

 

asp:Label ID="lblFirstName" runat="server" Text="<%# Resources.RadGrid.Template.FirstName %>"></asp:Label>

 


The label retains the value and display properly.

Thanks again for your help :)
Tags
Grid
Asked by
Aleksandar
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Mario Turcotte
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or