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

Reference and Update Controls in RadGrid EditForm Template

1 Answer 284 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carol
Top achievements
Rank 1
Carol asked on 10 Jun 2015, 02:12 AM

As I'm sure that you will understand, I have spent hours attempting various methods of self-solving this issue, but haven't been able to get it resolved, and am hoping that someone can give me a hand with this.  

My edit form contains only one field that excepts data from the user.  Once that value has been entered, or edited, on TextChanged the other textboxes should be populated with values resulting from calculations.  Four grid values are used in the calculations.

 I need to access each of the four provided values, perform the calculations, and load the results in the text boxes in the edit form, allowing the user to save the changes to refresh the grid.

 THIS DID NOT WORK: ClientEvents-OnBlur="calculateNetCash"

function onBlur(sender, args) {

    var textBox1;
    var textBox2;
    var textBoxTotal = $telerik.findControl(sender.get_parent().get_element(), "RadNumericTextBox3");
    var total;
 
    // get reference to the other RadNumericTextBox controls here
     
 
    // calculate the total
     
    // set the value for the last RadNumericTextBox
    textBoxTotal.set_value(total);

}

WHAT'S WORKING.  I can obtain the value of txtCashIn using  onChange = calculateNetCash(this)  and the values necessary for performing the calculation, using:

 Protected Sub OnItemDataBoundHandler(ByVal sender As Object, ByVal e As GridItemEventArgs)
        If e.Item.IsInEditMode AndAlso TypeOf e.Item Is GridEditFormItem Then
            Dim editForm As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
            Dim commissionRate As TextBox = DirectCast(editForm.FindControl("txtCommissionRate"), TextBox)
            Dim a As String
            a = commissionRate.Text
        End If

 End Sub

  These are my best test scenarios.  I figured that I could use hidden fields and then JavaScript to access the values for calculations.  But have not found any method, after hours of searching and testing, to reference the text boxes in the edit form template to store the values.

 

MY CODE

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="sdsGetDailyPayroll" Width="315px"
                    AutoGenerateColumns="False"
                    Skin="Bootstrap"
                    CssClass="RadGrid"
                    PageSize="5"
                    GridLines="None"
                    AllowPaging="True"
                    AllowSorting="True"
                    AllowAutomaticUpdates="True"
                    AllowAutomaticInserts="True"
                    AllowAutomaticDeletes="True"
                    ShowStatusBar="true"
                    OnItemDataBound="OnItemDataBoundHandler"
                    OnPreRender="RadGrid1_PreRender">

                    <MasterTableView
                        ShowFooter="false"
                        DataSourceID="sdsGetDailyPayroll"
                        DataKeyNames="EmpID"
                        CommandItemDisplay="Bottom"
                        GridLines="None"
                        AllowFilteringByColumn="False"
                        AllowSorting="True">

                        <PagerStyle PageSizes="3,4,5,6,7,8,9,10,25,50,100"
                            PageButtonCount="3"
                            PagerTextFormat=""
                            Width="315px"
                            Wrap="False" />

                        <Columns>
                            <telerik:GridBoundColumn UniqueName="PayrollDate" HeaderText="Date" DataField="PayrollDate"
                                DataFormatString="{0:d}">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="CashReceived" HeaderText="Cash In" DataField="CashReceived">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn UniqueName="DailyPayroll" HeaderText="Daily Payroll" DataField="DailyPayroll">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn UniqueName="PooledWages" HeaderText="Pooled?" DataField="PooledWages" Visible="false">
                                <HeaderStyle Width="25px"></HeaderStyle>
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn UniqueName="RentDeduction" HeaderText="Rent" DataField="RentDeduction" Visible="false">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn UniqueName="ExpenseDeduction" HeaderText="Expense" DataField="ExpenseDeduction" Visible="false">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn UniqueName="NetReceived" HeaderText="Net Cash In" DataField="NetReceived" Visible="false">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn UniqueName="Commission" HeaderText="Commission" DataField="Commission" Visible="false">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn UniqueName="DiscountCredit" HeaderText="Discounts" DataField="DiscountCredit" Visible="false">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn UniqueName="CommissionRate" HeaderText="Commission Rate" DataField="CommissionRate" Visible="false">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn UniqueName="ExpenseRate" HeaderText="ExpenseRate" DataField="ExpenseRate" Visible="false">
                            </telerik:GridBoundColumn>

                        </Columns>
                        <EditFormSettings EditFormType="Template">
                            <FormTemplate>
                                <div style="width: 280px; margin-right: 10px; margin-left: 10px; background-color: #f2f2f2; border: 2pt solid #D2D2D2; border-radius: 5px; padding: 5px">

                                    <table id="Table1" cellspacing="2" cellpadding="1" width="100%" border="0"
                                        rules="none" style="border-collapse: collapse;">

                                        <tr>
                                            <td>Payroll Date:</td>
                                            <td>
                                                <telerik:RadDatePicker ID="RadDatePicker1" runat="server" TabIndex="1"
                                                    Skin="Bootstrap"
                                                    MinDate="1/1/1900"
                                                    DbSelectedDate='<%# Bind("PayrollDate")%>'
                                                    Width="125px">
                                                </telerik:RadDatePicker>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td>Cash In:</td>
                                            <td>
                                                <asp:TextBox ID="txtCashIn" runat="server" TabIndex="2"
                                                    Text='<%# Bind("CashReceived")%>'
                                                    Width="75px"
                                                    OnChange="calculateNetCashIn(this)">
                                                </asp:TextBox>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td>Less Rent:</td>
                                            <td>
                                                <asp:TextBox ID="txtRentDeduction" runat="server" TabIndex="3"
                                                    Text='<%# Bind("RentDeduction")%>'
                                                    Width="75px">
                                                </asp:TextBox>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td>Less Expenses:</td>
                                            <td>
                                                <asp:TextBox ID="txtExpenseDeduction" runat="server" TabIndex="4"
                                                    Text='<%# Bind("ExpenseDeduction")%>'
                                                    Width="75px">
                                                </asp:TextBox>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td>NET CASH IN:</td>
                                            <td>
                                                <asp:TextBox ID="txtNetCashIn" runat="server" TabIndex="5"
                                                    Text='<%# Bind("NetReceived")%>'
                                                    Width="75px">
                                                </asp:TextBox></td>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td>Pooled Wages?</td>
                                            <td>
                                                <asp:CheckBox ID="CheckBox1" runat="server" TabIndex="6"
                                                    Checked='<%# Bind("PooledWages")%>'
                                                    Width="75px" />
                                            </td>
                                            <td>&nbsp;</td>
                                        </tr>

                                        <tr>
                                            <td>Commission</td>
                                            <td>
                                                <asp:TextBox ID="TextBox3" runat="server" TabIndex="7"
                                                    Text='<%# Bind( "Commission") %>'
                                                    Width="75px">
                                                </asp:TextBox>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td>Discount Credit:</td>
                                            <td>
                                                <asp:TextBox ID="TextBox7" runat="server" TabIndex="8"
                                                    Text='<%# Bind( "DiscountCredit") %>'
                                                    Width="75px">
                                                </asp:TextBox>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td>TOTAL PAYROLL:</td>
                                            <td>
                                                <asp:TextBox ID="TextBox10" runat="server" TabIndex="9"
                                                    Text='<%# Bind( "DailyPayroll") %>'
                                                    Width="75px">
                                                </asp:TextBox></td>
                                        </tr>

                                        <tr>
                                            <td>Commission Rate:</td>
                                            <td>
                                                <asp:TextBox ID="txtCommissionRate" runat="server" TabIndex="11"
                                                    Text='<%# Bind("CommissionRate")%>'
                                                    Width="75px">
                                                </asp:TextBox></td>
                                        </tr>
                                        <tr>
                                            <td>Expense Rate:</td>
                                            <td>
                                                <asp:TextBox ID="txtExpenseRate" runat="server" TabIndex="12"
                                                    Text='<%# Bind( "ExpenseRate") %>'
                                                    Width="75px">
                                                </asp:TextBox></td>
                                        </tr>
                                    </table>

                                </div>
                            </FormTemplate>
                        </EditFormSettings>

                    </MasterTableView>
                    <ClientSettings>
                        <Selecting AllowRowSelect="True" EnableDragToSelectRows="False"></Selecting>
                    </ClientSettings>
                </telerik:RadGrid>

THANK YOU

1 Answer, 1 is accepted

Sort by
0
Carol
Top achievements
Rank 1
answered on 10 Jun 2015, 05:33 PM

Well, after a full day of searching and trying various methods to resolve my issue and failing; and then finally reaching out to this forum, I finally resolved my issue, the next morning, after letting my mind rest.  And after three hours into this morning (repeating my efforts of yesterday), I found this beautiful solution, and now my project can move forward --- this after strongly doubting myself and wondering what I was doing with my life.  Note:  I had been using ASP.NET text boxes, but converted those to RadTextBox.

<EditFormSettings EditFormType="Template">
   <FormTemplate>
       <div>
      <table id="Table1" cellspacing="2" cellpadding="1" width="100%" border="0"
              rules="none" style="border-collapse: collapse;">
                 
                 <tr>
                     <td>Cash In:</td>
                     <td>
                        <telerik:RadTextbox ID="txtCashIn" runat="server" TabIndex="2"
                           Text='<%# Bind("CashReceived")%>'
                           Width="75px"
                           OnTextChanged="txtCashIn_TextChanged"
                            AutoPostBack="true">
                        </telerik:RadTextbox>
                     </td>
                 </tr>
            </table>
       </div>
   </FormTemplate>
</EditFormSettings>

 
Protected Sub txtCashIn_TextChanged(sender
As Object, e As EventArgs)

        Dim txtCashIn As RadTextBox = CType(sender, RadTextBox)

        Dim payrollGrid As WebControl = CType(txtCashIn.Parent, WebControl)

        Dim rentDeduction As RadTextBox = CType(payrollGrid.FindControl("txtRentDeduction"),
RadTextBox)
        Dim expenseDeduction As RadTextBox = CType(payrollGrid.FindControl("txtExpenseDeduction"), RadTextBox)
        Dim netCashIn As RadTextBox = CType(payrollGrid.FindControl("txtNetCashIn"),
RadTextBox)
        Dim commission As RadTextBox = CType(payrollGrid.FindControl("txtCommission"),
RadTextBox)
        Dim discountCredit As RadTextBox = CType(payrollGrid.FindControl("txtDiscountCredit"), RadTextBox)
        Dim totalPayroll As RadTextBox = CType(payrollGrid.FindControl("txtDailyPayroll"),
RadTextBox)
        Dim commissionRate As RadTextBox = CType(payrollGrid.FindControl("txtCommissionRate"), RadTextBox)
        Dim expenseRate As RadTextBox = CType(payrollGrid.FindControl("txtExpenseRate"),
RadTextBox)
         
expenseDeduction.Text = (CDbl(txtCashIn.Text) - (CDbl(txtRentDeduction) * 0.10))

        Dim intNetCashIn As Double = CDbl(txtCashIn.Text) - (CDbl(rentDeduction.Text) + CDbl(expenseDeduction.Text))
    
netCashIn.Text = intNetCashIn.ToString

    End Sub

Tags
Grid
Asked by
Carol
Top achievements
Rank 1
Answers by
Carol
Top achievements
Rank 1
Share this question
or