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

Dynamically Alter Edit FormTemplate on PageLoad

1 Answer 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tony
Top achievements
Rank 1
Tony asked on 28 Jan 2009, 03:50 AM
Hi, could someone help me with thist problem please.

I have a RadGrid on my page with a <EditFormSettings><FormTemplate> on it. (See below).  On Page load the Insert row is always shown (this was easy).
The problem I'm having is trying to edit the values of each of the controls as they change depending on what is in the db.
ie I'm trying to do something like this (Very simple example only):

Dim dt as DataTable = GetDTFromDataBase  
grid.Datasource= dt  
grid.databind  
 
If dt.rows.count =0 Then 
 grid.editItems.findcontrol("1").text = Now()  
Else 
 grid.editItems.findcontrol("1").text = dt.rows(0)("date") 
End If 


Actuall RadGrid
<telerik:RadGrid ID="rgActions" runat="server" AutoGenerateColumns="False" GridLines="None" 
    AllowAutomaticInserts="false" Skin="WebBlue">  
    <MasterTableView> 
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
        <EditFormSettings EditFormType="Template" > 
            <FormTemplate> 
                <%--<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="addAction" />--%> 
                <table> 
                    <tr> 
                        <td> 
                            <asp:Label ID="lblDate" runat="server" Text="Date:"></asp:Label></td>  
                        <td> 
                            <%--<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>onclick="ToggleFirstPopup()"--%> 
                            <telerik:RadDatePicker ID="rdpDate" runat="server" Culture="English (Australia)" Skin="WebBlue">  
                                <DateInput LabelCssClass="radLabelCss_WebBlue" Skin="WebBlue" > 
                                </DateInput> 
                                <Calendar Skin="WebBlue" > 
                                </Calendar> 
                            </telerik:RadDatePicker> 
                            <asp:RequiredFieldValidator ID="rfvDate" runat="server" ControlToValidate="rdpDate" 
                                ErrorMessage="Date is required" ValidationGroup="addAction">*</asp:RequiredFieldValidator></td>  
                        <td> 
                            <asp:Label ID="lblAction" runat="server" Text="Action:"></asp:Label></td>  
                        <td> 
                            <asp:TextBox ID="txtAction" runat="server"></asp:TextBox> 
                            <asp:RequiredFieldValidator ID="rfvAction" runat="server" ControlToValidate="txtAction" 
                                ErrorMessage="Action required" ValidationGroup="addAction">*</asp:RequiredFieldValidator></td>  
                    </tr> 
                    <tr> 
                        <td> 
                            <asp:Label ID="lblDateActioned" runat="server" Text="Date Actioned:"></asp:Label></td>  
                        <td> 
                            <%--<asp:TextBox ID="txtDateActioned" runat="server"></asp:TextBox>onclick="ToggleSecondPopup()"--%> 
                            <telerik:RadDatePicker ID="rdpDateActioned" runat="server" Skin="WebBlue">  
                                <DateInput LabelCssClass="radLabelCss_WebBlue" Skin="WebBlue" > 
                                </DateInput> 
                                <Calendar Skin="WebBlue">  
                                </Calendar> 
                            </telerik:RadDatePicker> 
                        </td> 
                        <td> 
                            <asp:Label ID="lblActionBy" runat="server" Text="Action By:"></asp:Label></td>  
                        <td> 
                            <%--<asp:TextBox ID="txtActionBy" runat="server"></asp:TextBox>--%> 
                            <telerik:RadComboBox ID="rcbActionBy" runat="server" Skin="WebBlue" DataSourceID="sdsEmployee" DataTextField="name" DataValueField="userID">  
                                <CollapseAnimation Duration="200" Type="OutQuint" /> 
                            </telerik:RadComboBox> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td colspan="4">  
                            <asp:TextBox ID="txtComment" runat="server" Width="399px"></asp:TextBox></td>  
                    </tr> 
                    <tr> 
                        <td> 
                            <asp:Label ID="lblNextAction" runat="server" Text="Next Action:"></asp:Label> 
                        </td> 
                        <td> 
                            <asp:TextBox ID="txtNextAction" runat="server"></asp:TextBox> 
                            <asp:RequiredFieldValidator ID="rfvNextAction" runat="server" ControlToValidate="txtNextAction" 
                                ErrorMessage="Next Action required" ValidationGroup="addAction">*</asp:RequiredFieldValidator></td>  
                        <td> 
                        </td> 
                        <td> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td> 
                            <asp:Label ID="lblNextToAction" runat="server" Text="Next To Action:"></asp:Label> 
                        </td> 
                        <td> 
                            <%--<asp:TextBox ID="txtNextToAction" runat="server"></asp:TextBox>--%> 
                            <telerik:RadComboBox ID="rcbNextToAction" AppendDataBoundItems="true" runat="server" Skin="WebBlue" DataSourceID="sdsEmployee" DataTextField="name" DataValueField="userID">  
                                <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                <Items> 
                                    <telerik:RadComboBoxItem Text=" -- Please select -- " Value="" /> 
                                </Items> 
                            </telerik:RadComboBox> 
                            <asp:RequiredFieldValidator ID="rfvNextToAction" runat="server" ControlToValidate="rcbNextToAction" 
                                ErrorMessage="Next To Action is required" ValidationGroup="addAction">*</asp:RequiredFieldValidator></td>  
                        <td> 
                            &nbsp;</td> 
                        <td> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td> 
                            <asp:Label ID="lblCC" runat="server" Text="CC:"></asp:Label></td>  
                        <td colspan="3">  
                            <telerik:RadComboBox ID="rcbCC1" AppendDataBoundItems="true" runat="server" Skin="WebBlue" DataSourceID="sdsEmployee" DataTextField="name" DataValueField="userID">  
                                <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                <Items> 
                                    <telerik:RadComboBoxItem Text=" -- Please select -- " Value="" /> 
                                </Items> 
                            </telerik:RadComboBox> 
                            <telerik:RadComboBox ID="rcbCC2" AppendDataBoundItems="true" runat="server" Skin="WebBlue" DataSourceID="sdsEmployee" DataTextField="name" DataValueField="userID">  
                                <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                <Items> 
                                    <telerik:RadComboBoxItem Text=" -- Please select -- " Value="" /> 
                                </Items> 
                            </telerik:RadComboBox> 
                            <telerik:RadComboBox ID="rcbCC3" AppendDataBoundItems="true" runat="server" Skin="WebBlue" DataSourceID="sdsEmployee" DataTextField="name" DataValueField="userID">  
                                <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                <Items> 
                                    <telerik:RadComboBoxItem Text=" -- Please select -- " Value="" /> 
                                </Items> 
                            </telerik:RadComboBox> 
                        </td> 
                    </tr> 
                    <tr> 
                        <td> 
                        </td> 
                        <td colspan="3">  
                            <asp:TextBox ID="txtCC" Rows="3" Width="200px" TextMode="multiLine" runat="server"></asp:TextBox> 
                        </td> 
                    </tr> 
                </table> 
                <asp:Button ID="btnAdd" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Add Action", "Update") %>' 
                    runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' ValidationGroup="addAction" /> 
                  
            </FormTemplate> 
        </EditFormSettings> 
        <Columns> 
            <telerik:GridTemplateColumn UniqueName="TemplateColumn">  
                <ItemTemplate> 
                    <table> 
                        <tr> 
                            <td> 
                                <asp:Label ID="lblDate" runat="server" Text="Date:"></asp:Label></td>  
                            <td> 
                                <asp:Label ID="txtDate" runat="server" Text='<%# Bind("dateLog") %>'></asp:Label></td>  
                            <td> 
                                <asp:Label ID="lblAction" runat="server" Text="Action:"></asp:Label></td>  
                            <td> 
                                <asp:Label ID="txtAction" runat="server" Text='<%# Bind("action") %>'></asp:Label></td>  
                        </tr> 
                        <tr> 
                            <td> 
                                <asp:Label ID="lblDateActioned" runat="server" Text="Date Actioned:"></asp:Label></td>  
                            <td> 
                                <asp:Label ID="txtDateActioned" runat="server" Text='<%# Bind("dateActioned") %>'></asp:Label></td>  
                            <td> 
                                <asp:Label ID="lblActionBy" runat="server" Text="Action By:"></asp:Label></td>  
                            <td> 
                                <asp:Label ID="txtActionBy" runat="server" Text='<%# Bind("ActionBy") %>'></asp:Label></td>  
                        </tr> 
                        <tr> 
                            <td colspan="4">  
                                <asp:Label ID="txtComment" runat="server" Width="399px" Text='<%# Bind("comment") %>'></asp:Label></td>  
                        </tr> 
                        <tr> 
                            <td> 
                                <asp:Label ID="lblNextAction" runat="server" Text="Next Action:"></asp:Label> 
                            </td> 
                            <td> 
                                <asp:Label ID="txtNextAction" runat="server" Text='<%# Bind("nextAction") %>'></asp:Label> 
                            </td> 
                            <td> 
                            </td> 
                            <td> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td> 
                                <asp:Label ID="lblNextToAction" runat="server" Text="Next To Action:"></asp:Label> 
                            </td> 
                            <td> 
                                <asp:Label ID="txtNextToAction" runat="server" Text='<%# Bind("nextToAction") %>'></asp:Label> 
                            </td> 
                            <td> 
                                &nbsp;</td> 
                            <td> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td> 
                                <asp:Label ID="lblCC" runat="server" Text="CC:"></asp:Label></td>  
                            <td> 
                                <asp:Label ID="txtCC" runat="server" Text='<%# Bind("cc") %>'></asp:Label></td>  
                            <td> 
                            </td> 
                            <td> 
                            </td> 
                        </tr> 
                    </table> 
                </ItemTemplate> 
            </telerik:GridTemplateColumn> 
        </Columns> 
    </MasterTableView> 
    <ClientSettings> 
        <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
    </ClientSettings> 
    <FilterMenu EnableTheming="True" Skin="WebBlue">  
        <CollapseAnimation Duration="200" Type="OutQuint" /> 
    </FilterMenu> 
</telerik:RadGrid> 

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Jan 2009, 06:53 PM
Hello Tony,

For the convenience of our community I paste my answer here.

I believe the most convenient way for such scenario would be to set the default values on ItemInsert event as shown in the following help article:

Inserting values using UserControl/FormTemplate

I hope this helps.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Tony
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or