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

Help getting Template form values

4 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike Wendell
Top achievements
Rank 1
Mike Wendell asked on 13 Apr 2011, 09:46 PM
Hello,

I am trying to do some manual form processing from the Template form with simple text boxes. I have followed several documented examples and I am not getting any values back from my posted form. Can anybody help me understand what might be wrong here?

I would like to do some basic processing like this:

http://www.telerik.com/community/code-library/aspnet-ajax/grid/manual-insert-update-delete-using-formtemplate-and-sql-backend.aspx

I am using a custom business object to interface with my database and all I want to do is populate the object from the form values and call a procedure to handle the data processing on the backend. Simple enough right?

Protected Sub gridAdjustments_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
        Try
            Dim insertedItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
            Dim thisAdjustmentDetail As New AdjustmentDetail()          

            thisAdjustmentDetail.ChangedSSN = (TryCast(insertedItem.FindControl("txtSSN"), TextBox)).Text
            thisAdjustmentDetail.FirstName = (TryCast(insertedItem.FindControl("txtFirstName"), TextBox)).Text
            thisAdjustmentDetail.MiddleName = (TryCast(insertedItem.FindControl("txtMiddleName"), TextBox)).Text
            thisAdjustmentDetail.LastName = (TryCast(insertedItem.FindControl("txtLastName"), TextBox)).Text
            Dim qtrlyEarnings As String = (TryCast(insertedItem.FindControl("txtQuarterlyEarnings"), TextBox)).Text
            If qtrlyEarnings <> "" Then
                thisAdjustmentDetail.QuarterlyEarnings = Decimal.Parse(qtrlyEarnings)
            Else
                thisAdjustmentDetail.QuarterlyEarnings = 0D
            End If

            Dim insertDetailRecord As New DetailTable()
            insertDetailRecord.InsertDetail(thisAdjustmentDetail)
 
            thisAdjustmentDetail = Nothing
            insertDetailRecord = Nothing
        Catch ex As Exception
            gridAdjustments.Controls.Add(New LiteralControl("Unable to insert item: " + ex.Message))
            e.Canceled = True
        End Try
    End Sub

Any of the statements where I do the TryCast to grab the values from the EditForm return empty values. I am probably missing something obvious, so I hope you can help.

Thanks in advance,
Mike

4 Answers, 1 is accepted

Sort by
0
Mike Wendell
Top achievements
Rank 1
answered on 14 Apr 2011, 04:10 PM
Apologies for bumping a topic with zero replies. Not sure what the policy is on that here. Anyone have any ideas here? I hate to abandon the grid for the standard .NET controls, but will be forced to if I can't get this working with our custom business objects.
0
Mike Wendell
Top achievements
Rank 1
answered on 15 Apr 2011, 08:27 PM
OK, another try. here is my RadGrid:

<telerik:RadGrid Width="750px" CellPadding="0" CellSpacing="0" ID="gridAdjustments"
                                runat="server" AllowFilteringByColumn="False" AllowPaging="True" AllowSorting="True"
                                AllowAutomaticInserts="false" AllowAutomaticDeletes="false" AllowAutomaticUpdates="false"
                                AutoGenerateColumns="False" OnItemDataBound="gridAdjustments_ItemDataBound" OnItemDeleted="gridAdjustments_ItemDeleted"
                                OnItemInserted="gridAdjustments_ItemInserted" OnItemUpdated="gridAdjustments_ItemUpdated"
                                OnItemCommand="gridAdjustments_ItemCommand" OnPreRender="gridAdjustments_PreRender"
                                OnDataBound="gridAdjustments_DataBound" OnInsertCommand="gridAdjustments_InsertCommand"
                                OnUpdateCommand="gridAdjustments_UpdateCommand" OnDeleteCommand="gridAdjustments_DeleteCommand"
                                GridLines="None" Skin="Office2007" ShowFooter="True">
                                <HeaderContextMenu EnableTheming="True" Skin="">
                                    <CollapseAnimation Duration="200" Type="OutQuint" />
                                </HeaderContextMenu>
                                <PagerStyle Mode="NextPrevAndNumeric" />
                                <ItemStyle BorderWidth="0" />
                                <AlternatingItemStyle BorderWidth="0" />
                                <MasterTableView CommandItemDisplay="Bottom" DataKeyNames="ID">
                                    <ItemStyle BorderWidth="0" />
                                    <AlternatingItemStyle BorderWidth="0" />
                                    <RowIndicatorColumn>
                                        <HeaderStyle Width="20px" />
                                    </RowIndicatorColumn>
                                    <ExpandCollapseColumn>
                                        <HeaderStyle Width="20px" />
                                    </ExpandCollapseColumn>
                                    <Columns>
                                        <telerik:GridNumericColumn Visible="false" DataField="id" UniqueName="id">
                                        </telerik:GridNumericColumn>
                                        <telerik:GridMaskedColumn HeaderText="SSN" Mask="###-##-####" DataField="SSN" UniqueName="SSN"
                                            SortExpression="SSN">
                                            <ItemStyle Width="60px" BorderWidth="0" />
                                        </telerik:GridMaskedColumn>
                                        <telerik:GridBoundColumn HeaderText="First Name" DataField="FirstName" UniqueName="FirstName"
                                            SortExpression="FirstName">
                                            <ItemStyle Width="100px" BorderWidth="0" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="Middle Name" DataField="MiddleName" UniqueName="MiddleName"
                                            SortExpression="MiddleName">
                                            <ItemStyle Width="80px" BorderWidth="0" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="Last Name" DataField="LastName" UniqueName="LastName"
                                            SortExpression="LastName">
                                            <ItemStyle Width="100px" BorderWidth="0" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn Visible="false" DataField="SeasonalIndicator" UniqueName="SeasonalIndicator">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="Wages" DataField="QuarterlyEarnings" DataFormatString="{0:C2}"
                                            UniqueName="QuarterlyEarnings" SortExpression="QuarterlyEarnings">
                                            <ItemStyle Width="100px" BorderWidth="0" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" Display="false">
                                        </telerik:GridEditCommandColumn>
                                    </Columns>
                                    <EditFormSettings EditFormType="Template">
                                        <FormTemplate>
                                            <table width="100%" cellspacing="2" cellpadding="1" border="0" rules="none" style="border-collapse: collapse;
                                                background: white;">
                                                <tr>
                                                    <td style="height: 6px;" colspan="7">
                                                          
                                                    </td>
                                                </tr>
                                                <tr class="EditFormHeader">
                                                    <td style="width: 2px;">
                                                          
                                                    </td>
                                                    <td style="width: 100px;">
                                                        <asp:Label ID="lblSSN" runat="server" Text="SSN"></asp:Label>
                                                    </td>
                                                    <td style="width: 100px;">
                                                        <asp:Label ID="lblFName" runat="server" Text="First Name"></asp:Label>
                                                    </td>
                                                    <td style="width: 50px;">
                                                        <asp:Label ID="lblMName" runat="server" Text="Middle Name"></asp:Label>
                                                    </td>
                                                    <td style="width: 100px;">
                                                        <asp:Label ID="lblLName" runat="server" Text="Last Name"></asp:Label>
                                                    </td>
                                                    <%If Session("IsSeasonal") Then%>
                                                    <td id="seasonalLabel" style="width: 50px;">
                                                        <asp:Label ID="lblSeasonalIndicator" runat="server" Text="Seasonal"></asp:Label>
                                                    </td>
                                                    <%End If%>
                                                    <td style="width: 50px;">
                                                        <asp:Label ID="lblWages" runat="server" Text="Wages"></asp:Label>
                                                    </td>
                                                    <td style="width: 2px;">
                                                          
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 2px;">
                                                          
                                                        <asp:HiddenField ID="hidFldId" runat="server" Value='<%# Eval("id") %>' />
                                                        <asp:HiddenField ID="hidConfID" runat="server" Value='<%# Eval("confirmationID") %>' />
                                                        <asp:HiddenField ID="hidAdjustType" runat="server" Value='<%# Eval("adjustmentType") %>' />
                                                        <asp:HiddenField ID="hidAdjustID" runat="server" Value='<%# Eval("adjustmentID") %>' />
                                                        <asp:HiddenField ID="hidSeasonalInd" runat="server" Value='<%# Eval("seasonalIndicator") %>' />                                                       
                                                    </td>
                                                    <td style="width: 101px;">
                                                        <asp:HiddenField ID="changedSSN" runat="server" Value='<%# Eval("ChangedSSN") %>' OnPreRender="hidSSN_PreRender" />
                                                        <asp:TextBox ID="txtSSN" runat="server" Width="101px" Text='<%# Bind("SSN") %>' />
                                                    </td>
                                                    <td style="width: 100px;">
                                                        <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>' CssClass="textboxEmployerName"></asp:TextBox>
                                                    </td>
                                                    <td style="width: 50px;">
                                                        <asp:TextBox ID="txtMiddleName" runat="server" Text='<%# Bind("MiddleName") %>' CssClass="textboxEmployerName"></asp:TextBox>
                                                    </td>
                                                    <td style="width: 100px;">
                                                        <asp:TextBox ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>' CssClass="textboxEmployerName"></asp:TextBox>
                                                    </td>
                                                    <%  If Session("IsSeasonal") Then
                                                            seasonalWidth = "8"%>
                                                    <td id="seasonalDDL" style="width: 50px;">
                                                        <asp:DropDownList ID="ddlSeasonalIndicator" runat="server" SelectedValue='<%# Bind("SeasonalIndicator") %>'
                                                            CssClass="dropDownSeasonalIndicator" Width="100%" Enabled="True">
                                                            <asp:ListItem Value="Y">Y</asp:ListItem>
                                                            <asp:ListItem Value="N">N</asp:ListItem>
                                                            <asp:ListItem Value=""></asp:ListItem>
                                                        </asp:DropDownList>
                                                    </td>
                                                    <% End If%>
                                                    <td style="width: 50px;">
                                                        <asp:TextBox ID="txtQuarterlyEarnings" runat="server" Text='<%# Bind("QuarterlyEarnings") %>'
                                                            CssClass="textboxEmployerName"></asp:TextBox>
                                                    </td>
                                                    <td style="width: 2px;">
                                                          
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="height: 6px;" colspan="7">
                                                          
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="right" colspan="<%= seasonalWidth %>">
                                                        <asp:Button ID="btnUpdate" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update")  %>'
                                                            runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update")  %>' /> 
                                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                            CommandName="Cancel"></asp:Button>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="height: 6px;" colspan="<%= seasonalWidth %>">
                                                          
                                                    </td>
                                                </tr>
                                            </table>
                                        </FormTemplate>
                                    </EditFormSettings>
                                </MasterTableView>
                                <ClientSettings>
                                    <ClientEvents OnRowDblClick="RowDblClick" />
                                </ClientSettings>
                                <FilterMenu EnableTheming="True" Skin="Office2007">
                                    <CollapseAnimation Duration="200" Type="OutQuint" />
                                </FilterMenu>
                            </telerik:RadGrid>

And here is the InsertCommand:

Protected Sub gridAdjustments_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
        Try
            Dim insertedItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
            Dim thisAdjustmentDetail As New AdjustmentDetail()
            
            thisAdjustmentDetail.ChangedSSN = (TryCast(insertedItem.FindControl("txtSSN"), TextBox)).Text
            thisAdjustmentDetail.SeasonalIndicator = False
            If Session("IsSeasonal") Then
                thisAdjustmentDetail.SeasonalIndicator = IIf((TryCast(insertedItem.FindControl("ddlSeasonalIndicator"), DropDownList)).SelectedValue = "Y", True, False)
            End If
            thisAdjustmentDetail.FirstName = (TryCast(insertedItem.FindControl("txtFirstName"), TextBox)).Text
            thisAdjustmentDetail.MiddleName = (TryCast(insertedItem.FindControl("txtMiddleName"), TextBox)).Text
            thisAdjustmentDetail.LastName = (TryCast(insertedItem.FindControl("txtLastName"), TextBox)).Text
            Dim qtrlyEarnings As String = (TryCast(insertedItem.FindControl("txtQuarterlyEarnings"), TextBox)).Text
            If qtrlyEarnings <> "" Then
                thisAdjustmentDetail.QuarterlyEarnings = Decimal.Parse(qtrlyEarnings)
            Else
                thisAdjustmentDetail.QuarterlyEarnings = 0D
            End If
            thisAdjustmentDetail.CreateDate = DateTime.Now()
            thisAdjustmentDetail.UpdateDate = DateTime.Now()
            thisAdjustmentDetail.ActiveIndicator = 1
            thisAdjustmentDetail.DeleteIndicator = "N"
 
            Dim insertDetailRecord As New AdjustmentDetailTable()
            insertDetailRecord.InsertAdjustmentDetail(thisAdjustmentDetail)
 
            thisAdjustmentDetail = Nothing
            insertDetailRecord = Nothing
        Catch ex As Exception
            gridAdjustments.Controls.Add(New LiteralControl("Unable to insert wage item: " + ex.Message))
            e.Canceled = True
        End Try
    End Sub

None of the statements that should be accessing form values in my Template Form are returning data. They are all null or ""

Please help!
0
Mike Wendell
Top achievements
Rank 1
answered on 18 Apr 2011, 04:07 PM
I guess the forums are kind of dead now then? I will submit a support ticket.
0
Tsvetina
Telerik team
answered on 19 Apr 2011, 10:04 AM
Hi Mike,

I am posting the answer from your support ticket here for others to see if interested. Anyway, I would ask you to post only in the formal support ticket if you want to get back to us, so that we avoid duplicate posts. Thank you.

I looked at your code and it seems to be correct. You can see that our documentation recommends the same approach for inserts and updates using form template.

One thing that I did not see in your code was how you are binding your grid, so could you please confirm that you are using advanced data-binding and you do not call DataBind() anywhere in your code? Also, when you debug your code, is only the text value empty or the whole textbox controls come back as null?

As for AJAX, you could rule it out as a possible cause of the issue by temporarily setting EnableAJAX="false" for the RadAjaxManager and see what happens.

Best wishes,
Tsvetina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Mike Wendell
Top achievements
Rank 1
Answers by
Mike Wendell
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or