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

EditForm doesn't shows values for update

6 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jaime
Top achievements
Rank 1
Jaime asked on 17 Oct 2008, 05:16 PM
Hello...

Now I'm having problems with EditForm. I have added the following template. When I click the pencil to edit a row of the RadGrid (databounded to a datasource) all TextBox fields appear empty.

Any help woul be greatly appreciated

<EditFormSettings EditFormType="Template">  
<EditColumn UniqueName="EditCommandColumn1"></EditColumn> 
    <FormTemplate> 
        <rad:RadPanelbar ID="pnlUsuario" runat="server" Skin="Default2006" Width="100%" ValidationGroup="grpSeleccion">  
            <Items> 
                <rad:RadPanelItem runat="server" Text="Datos B&#225;sicos">  
                    <ItemTemplate> 
                        <table style="width: 360px">  
                            <tr> 
                                <td class="label" style="width: 110px">Nombre</td> 
                                <td style="width: 250px"><asp:TextBox CssClass="texto" MaxLength="50" Columns="50" ID="txtNombre" Text='<%# Bind("FirstName") %>' runat="server"></asp:TextBox> 
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtNombre" 
                                        ErrorMessage="Debe ingresar el nombre del usuario" SetFocusOnError="True" Display="Dynamic">*</asp:RequiredFieldValidator></td>  
                            </tr> 
                            <tr> 
                                <td class="label" style="width: 110px">Apellidos</td> 
                                <td style="width: 240px"><asp:TextBox CssClass="texto" MaxLength="50" Columns="50" ID="txtApellidos" Text='<%# Bind("LastName") %>' runat="server"></asp:TextBox> 
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtApellidos" 
                                        ErrorMessage="Debe ingresar los apellidos del usuario" SetFocusOnError="True" Display="Dynamic">*</asp:RequiredFieldValidator></td>  
                            </tr> 
                            <tr> 
                                <td class="label" style="width: 110px">Nombre Usuario</td> 
                                <td style="width: 240px"><asp:TextBox CssClass="texto" MaxLength="50" Columns="50" ID="txtUsername" Text='<%# Bind("UserName") %>' runat="server"></asp:TextBox> 
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtUsername" 
                                        ErrorMessage="Debe ingresar el nombre de usuario que se usará para conectarse al sistema" 
                                        SetFocusOnError="True" Display="Dynamic">*</asp:RequiredFieldValidator></td>  
                            </tr> 
                            <tr> 
                                <td class="label" style="width: 110px">Contraseña</td> 
                                <td style="width: 240px"><asp:TextBox CssClass="texto" MaxLength="50" Columns="52" ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox> 
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtPassword" 
                                        Display="Dynamic" ErrorMessage="Debe ingresar la contraseña del usuario" SetFocusOnError="True">*</asp:RequiredFieldValidator></td>  
                            </tr> 
                            <tr> 
                                <td class="label" style="width: 110px">Repita Contraseña</td> 
                                <td style="width: 240px"><asp:TextBox CssClass="texto" MaxLength="50" Columns="52" ID="txtPassword2" TextMode="Password" runat="server"></asp:TextBox> 
                                    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtPassword" 
                                        ControlToValidate="txtPassword2" ErrorMessage="Las contraseñas no coinciden" 
                                        SetFocusOnError="True" Display="Dynamic">*</asp:CompareValidator></td>  
                            </tr> 
                            <tr> 
                                <td class="label" style="width: 110px">RUT</td> 
                                <td style="width: 240px"><asp:TextBox CssClass="texto" MaxLength="10" Columns="12" ID="txtRUT" Text='<%# Bind("RUT") %>' runat="server"></asp:TextBox>&nbsp;<asp:TextBox CssClass="texto" MaxLength="1" Columns="2" ID="txtDV" Text='<%# Bind("DV") %>' runat="server"></asp:TextBox> 
                                    <fw:rutvalidator id="RutValidator1" runat="server" controltovalidate="txtRUT" controltovalidatedv="txtDV" 
                                        errormessage="El RUT fue ingresado incorrectamente" setfocusonerror="True" Display="Dynamic">*</fw:rutvalidator> 
                                </td> 
                            </tr> 
                            <tr> 
                                <td class="label" style="width: 110px">E-mail</td> 
                                <td style="width: 240px"><asp:TextBox CssClass="texto" MaxLength="50" Columns="50" ID="txtEmail" Text='<%# Bind("Email") %>' runat="server"></asp:TextBox> 
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail" 
                                        ErrorMessage="El e-mail fue ingresado incorrectamnte" SetFocusOnError="True" 
                                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic">*</asp:RegularExpressionValidator></td>  
                            </tr> 
                        </table> 
                    </ItemTemplate> 
                </rad:RadPanelItem> 
                <rad:RadPanelItem runat="server" Text="Sistemas">  
                    <ItemTemplate> 
                        <asp:CheckBoxList ID="chkSistemas" runat="server" DataSourceID="objSistemas" DataTextField="ApplicationName" 
                            DataValueField="ApplicationId" RepeatColumns="5">  
                        </asp:CheckBoxList> 
                    </ItemTemplate> 
                </rad:RadPanelItem> 
            </Items> 
        </rad:RadPanelbar> 
        <br />&nbsp;  
        <asp:ImageButton ID="btnAlmacenar" runat="server" ImageUrl="~/images/almacenar.gif" CommandName="Update" /> 
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
        <asp:ImageButton ID="btnVolver" runat="server" CausesValidation="false" ImageUrl="~/images/volver.gif" CommandName="Cancel" /> 
        <br /> 
    </FormTemplate> 
</EditFormSettings> 
 

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 20 Oct 2008, 06:23 AM
Hi Jaime,

How the grid is bound in your case? Are you using DataSourceID?

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Princy
Top achievements
Rank 2
answered on 20 Oct 2008, 06:38 AM
Hi,

Try using  DataBinder.Eval expressions in the template's definition:
<%# DataBinder.Eval(Container.DataItem, "ColumnName") %>


Thanks,
Princy
0
Jaime
Top achievements
Rank 1
answered on 20 Oct 2008, 12:22 PM
Hello !

Vlad:
Yes, I am using DataSourceID bound to an ObjectDataSource.

Princy:
I tried it, but it didn't work.

I used
                            <tr> 
                                <td class="label" style="width: 110px">Nombre</td> 
                                <td style="width: 250px"><asp:TextBox CssClass="texto" MaxLength="50" Columns="50" ID="txtNombre" Text='<%# DataBinder.Eval(Container.DataItem, "FirstName") %>' runat="server"></asp:TextBox> 
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtNombre" 
                                        ErrorMessage="Debe ingresar el nombre del usuario" SetFocusOnError="True" Display="Dynamic">*</asp:RequiredFieldValidator></td>  
                            </tr> 
 

But that text field is still appearing empty when I enter edit mode. Other fact I could mention. If I write the name of a non-existent column, no exception occurs so I suppose the only thing that is happening is to show the form, not to bind the data.

Thanks
Jaime
0
Jaime
Top achievements
Rank 1
answered on 20 Oct 2008, 03:47 PM
I have implemented EditCommand of the GridView which actually is called when I press the pencil icon.

By using immediate window I saw the content of e.Item property:

e.Item  
{Telerik.WebControls.GridDataItem}  
    [Telerik.WebControls.GridDataItem]: {Telerik.WebControls.GridDataItem}  
    base {Telerik.WebControls.GridTableRow}: {Telerik.WebControls.GridDataItem}  
    CanExpand: false  
    ClientRowIndex: -1  
    DataItem: null  
    DataSetIndex: 19  
    Display: true  
    Edit: true  
    Expanded: false  
    GroupIndex: "18"  
    HasChildItems: false  
    IsDataBound: true  
    IsInEditMode: false  
    ItemIndex: 19  
    ItemIndexHierarchical: "19"  
    ItemType: AlternatingItem  
    OwnerGridID: "grdUsuarios"  
    OwnerID: "grdUsuarios_ctl01"  
    OwnerTableView: {Telerik.WebControls.GridTableView}  
    RowIndex: 40  
    Selected: false 

I don't know if this can help to solve the problem, but just in case

Jame
0
Jaime
Top achievements
Rank 1
answered on 20 Oct 2008, 04:32 PM
I have found the problem !!!

The fact is that I have a RadPanelBar inside the FormTemplate and inside it, I placed the TextBox controls.

To make a test, I placed a TextBox outside the RadPanelBar and the TextBox was correctly filled with the data.

The question now is: how can I use RadPanelBar inside the form template? I need to group the elements that are edited and instead of using HTML tables and implementing expand and collapse by myself, I found RadPanelBar a good alternative.

Thanks
Jaime
0
Iana Tsolova
Telerik team
answered on 22 Oct 2008, 12:21 PM
Hi Jaime,

When the TextBoxes used in the edit form are nested in another control which runs at server, it is expected that the binding expression does not work properly. Therefore you have to set the textbox controls value in the ItemDataBound event handler of the grid:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
{  
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)  
    {  
        GridEditFormItem item = e.Item as GridEditFormItem;  
        RadPanelBar panelBar = item.FindControl("pnlUsuario"as RadPanelBar;  
        TextBox txt1 = panelBar.Items[0].FindControl("txtNombre"as TextBox;  
        txt1.Text = (item.DataItem as DataRowView)["FirstName"].ToString();  
        ....  
    }  

Find more about RadGrid editing and accessing cells and rows in the following resources:
http://www.telerik.com/help/aspnet-ajax/grdupdatingvaluesusercontrolformtemplate.html
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

Let me know if this helps.

Greetings,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Jaime
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Princy
Top achievements
Rank 2
Jaime
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or