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

[Solved] Edit Form control issues

1 Answer 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam Hager
Top achievements
Rank 1
Adam Hager asked on 08 Dec 2009, 04:17 PM
I have a grid with an edit form template.  I am having a heck of a time binding the controls in the edit form when a row is selected.  When I try and perform a find control the control is always null.  Please help!
<asp:ObjectDataSource ID="CurrencyDataSource" runat="server"   
                SelectMethod="RetrieveLookupsByLookupTypeId"   
                TypeName="Graebel.RITS.Components.BusinessManagers.LookupManager">  
                <SelectParameters> 
                    <asp:Parameter DefaultValue="106" Name="lookupTypeId" Type="Int32" /> 
                </SelectParameters> 
            </asp:ObjectDataSource> 
            <asp:ScriptManager ID="ScriptManager1" runat="server">  
            </asp:ScriptManager> 
            <telerik:RadGrid ID="RemittanceGrid" runat="server" AllowAutomaticInserts="True" 
                AllowAutomaticUpdates="True" AllowSorting="True" AutoGenerateColumns="False" 
                GridLines="None" Skin="Telerik" ShowStatusBar="True"   
                OnItemCommand="RemittanceGrid_ItemCommand" AutoGenerateEditColumn="True"   
                onneeddatasource="RemittanceGrid_NeedDataSource"   
                onitemdatabound="RemittanceGrid_ItemDataBound">  
                <pagerstyle mode="NumericPages" alwaysvisible="true" /> 
                <mastertableview width="100%" commanditemdisplay="Top" datakeynames="VendorRemittanceId" 
                    allowautomaticinserts="True">  
                    <Columns> 
                        <telerik:GridBoundColumn UniqueName="RemittanceId" DataField="Remittance.RemittanceId">  
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn HeaderText="Bank Name" UniqueName="BankName" DataField="Remittance.BankName">  
                        <HeaderStyle HorizontalAlign="Center" /> 
                        <ItemStyle HorizontalAlign="Center" /> 
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn HeaderText="Account #" UniqueName="Account" DataField="Remittance.AccountNumber">  
                        <HeaderStyle HorizontalAlign="Center" /> 
                        <ItemStyle HorizontalAlign="Center" /> 
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn HeaderText="Currency" UniqueName="Currency" DataField="Lookups.Text.Description">  
                        <HeaderStyle HorizontalAlign="Center" /> 
                        <ItemStyle HorizontalAlign="Center" /> 
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn HeaderText="Sequence" UniqueName="Sequence" DataField="SequenceNum">  
                        <HeaderStyle HorizontalAlign="Center" /> 
                        <ItemStyle HorizontalAlign="Center" /> 
                        </telerik:GridBoundColumn> 
                    </Columns> 
                    <EditFormSettings EditFormType="Template">  
                        <FormTemplate> 
                            <table style="width: 100%;">  
                                <tr> 
                                    <td> 
                                        Currency:  
                                    </td> 
                                    <td> 
                                        <asp:DropDownList AppendDataBoundItems="true" ID="DropDownList1" runat="server" DataSourceID="CurrencyDataSource"   
                                        DataTextField="Description" DataValueField="LookupId" > 
                                        <asp:ListItem Text="Select" Value=""></asp:ListItem> 
                                        </asp:DropDownList> 
                                    </td> 
                                    <td> 
                                        Non-Currency Specific Vendor:  
                                    </td> 
                                    <td> 
                                        <asp:CheckBox ID="CheckBox1" runat="server"  /> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td> 
                                        Bank Sequence:  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox> 
                                    </td> 
                                    <td> 
                                        Account #:  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td> 
                                        Payable Name:  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox3" runat="server" ></asp:TextBox> 
                                    </td> 
                                    <td> 
                                        ABA Transit Route #:  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox4" runat="server" ></asp:TextBox> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td> 
                                        Swift Code:  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox5" runat="server" ></asp:TextBox> 
                                    </td> 
                                    <td> 
                                        ISO Package Received:  
                                    </td> 
                                    <td> 
                                        <asp:CheckBox ID="CheckBox2" runat="server" /> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td> 
                                        Bank Name:  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox6" runat="server" ></asp:TextBox> 
                                    </td> 
                                    <td> 
                                        Bank Address:  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox7" runat="server" ></asp:TextBox> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td> 
                                        &nbsp;  
                                    </td> 
                                    <td> 
                                        &nbsp;  
                                    </td> 
                                    <td> 
                                        &nbsp;  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox8" runat="server" ></asp:TextBox> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td> 
                                        City:  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox9" runat="server" ></asp:TextBox> 
                                    </td> 
                                    <td> 
                                        &nbsp;  
                                    </td> 
                                    <td> 
                                        <uc1:StateCountryFields ID="m_stateCountryFields" runat="server" /> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td> 
                                        Zip:  
                                    </td> 
                                    <td> 
                                        <asp:TextBox ID="TextBox10" runat="server" ></asp:TextBox> 
                                    </td> 
                                    <td> 
                                        &nbsp;  
                                    </td> 
                                    <td> 
                                        &nbsp;  
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td> 
                                        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>  
                                        </asp:Button> 
                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" 
                                            CommandName="Cancel"></asp:Button> 
                                    </td> 
                                    <td> 
                                        &nbsp;  
                                    </td> 
                                    <td> 
                                        &nbsp;  
                                    </td> 
                                    <td> 
                                        &nbsp;  
                                    </td> 
                                </tr> 
                            </table> 
                        </FormTemplate> 
                    </EditFormSettings> 
                </mastertableview> 
            </telerik:RadGrid> 
protected void RemittanceGrid_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            if (e.Item is GridCommandItem && e.Item.IsInEditMode)  
            {  
                DropDownList currency = (DropDownList)e.Item.FindControl("ddlCurrency");  
                HiddenField vrId = (HiddenField)e.Item.FindControl("VendorRemittanceId");  
                CheckBox isGlobal = (CheckBox)e.Item.FindControl("chkGlobalCurrency");  
                RadNumericTextBox sequenceNum = (RadNumericTextBox)e.Item.FindControl("SequenceNum");  
                TextBox ABA = (TextBox)e.Item.FindControl("m_tbABATransitNumber");  
                TextBox accountNumber = (TextBox)e.Item.FindControl("m_tbAccountNumber");  
                TextBox payableName = (TextBox)e.Item.FindControl("m_tbPayableName");  
                TextBox swiftCode = (TextBox)e.Item.FindControl("m_tbSwiftCode");  
                TextBox bankName = (TextBox)e.Item.FindControl("m_tbBankName");  
                CheckBox ISO = (CheckBox)e.Item.FindControl("m_cbISOPackageReceived");  
                UserControl stateCountry = (UserControl)e.Item.FindControl("m_stateCountryFields");  
                TextBox address1 = (TextBox)e.Item.FindControl("m_tbBankAddress");  
                TextBox address2 = (TextBox)e.Item.FindControl("m_tbBankAddress2");  
                TextBox city = (TextBox)e.Item.FindControl("m_tbBankCity");  
                TextBox zip = (TextBox)e.Item.FindControl("m_tbBankPostalCode");  
                HiddenField addressId = (HiddenField)e.Item.FindControl("AddressId");  
 
                VendorPaymentInfoManager vpim = new VendorPaymentInfoManager();  
                int RemittanceId = 0;  
                Int32.TryParse(e.Item.Cells[2].Text, out RemittanceId);  
                Graebel.RITS.Components.RitsEntityDal.VendorRemittance remit = new Graebel.RITS.Components.RitsEntityDal.VendorRemittance();  
                Graebel.RITS.Components.RitsEntityDal.Addresses remitAddress = new Addresses();  
                if (RemittanceId != 0)  
                {  
                    remit = vpim.GetRemittanceInfo(RemittanceId);  
                    remitAddress = vpim.GetRemittanceAddressInfo(remit.Remittance.RemittanceId);  
                }  
                if (currency != null)  
                {  
                    currency.SelectedValue = remit.Lookups.LookupId.ToString();  
                }  
                if (vrId != null)  
                {  
                    vrId.Value = remit.VendorRemittanceId.ToString();  
                }  
                if (isGlobal != null)  
                {  
                    isGlobal.Checked = remit.IsGlobalCurrency;  
                }  
                if (sequenceNum != null)  
                {  
                    sequenceNum.Value = remit.SequenceNum;  
                }  
                if (ABA != null)  
                {  
                    ABA.Text = remit.Remittance.ABATransitRoutingNumber;  
                }  
                if (accountNumber != null)  
                {  
                    accountNumber.Text = remit.Remittance.AccountNumber;  
                }  
                if (payableName != null)  
                {  
                    payableName.Text = remit.Remittance.PayableName;  
                }  
                if (swiftCode != null)  
                {  
                    swiftCode.Text = remit.Remittance.SWIFTCode;  
                }  
                if (bankName != null)  
                {  
                    bankName.Text = remit.Remittance.BankName;  
                }  
                if (ISO != null)  
                {  
                    ISO.Checked = remit.Remittance.HasISOPackage.Value;  
                }  
                if (stateCountry != null)  
                {  
                    RITS.Web.Controls.TypedDropDownList state = (RITS.Web.Controls.TypedDropDownList)stateCountry.FindControl("m_ddlState");  
                    RITS.Web.Controls.TypedDropDownList country = (RITS.Web.Controls.TypedDropDownList)stateCountry.FindControl("m_ddlCountry");  
                    state.SelectedValue = remitAddress.States.StateId.ToString();  
                    country.SelectedValue = remitAddress.Countries.CountryId.ToString();  
                }  
                if (address1 != null)  
                {  
                    address1.Text = remitAddress.Address1;  
                }  
                if (address2 != null)  
                {  
                    address2.Text = remitAddress.Address2;  
                }  
                if (city != null)  
                {  
                    city.Text = remitAddress.City;  
                }  
                if (zip != null)  
                {  
                    zip.Text = remitAddress.Zip;  
                }  
                if (addressId != null)  
                {  
                    addressId.Value = remitAddress.AddressId.ToString();  
                }  
            }  
        }  
 
protected void RemittanceGrid_ItemCommand(object source, GridCommandEventArgs e)  
        {  
            if (e.CommandName == RadGrid.InitInsertCommandName)  
            {  
 
                e.Canceled = true;  
                //Prepare an IDictionary with the predefined values  
                System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();  
                newValues["IsGlobalCurrency"] = false;  
                newValues["Remittance.AccountNumber"] = string.Empty;  
                newValues["Remittance.PayableName"] = string.Empty;  
                newValues["Remittance.ABATransitRoutingNumber"] = string.Empty;  
                newValues["Remittance.SWIFTCode"] = string.Empty;  
                newValues["Remittance.HasISOPackage"] = false;  
                newValues["Remittance.BankName"] = string.Empty;  
                newValues["Remittance.Addresses.Address1"] = string.Empty;  
                newValues["Remittance.Addresses.Address2"] = string.Empty;  
                newValues["Remittance.Addresses.City"] = string.Empty;  
                newValues["Remittance.Addresses.Zip"] = string.Empty;  
                newValues["Lookups.LookupId"] = string.Empty;  
 
                //Insert the item and rebind  
                e.Item.OwnerTableView.InsertItem(newValues);  
            }              
        } 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Dec 2009, 06:36 AM
Hello Adam,

You can access the controls in the EditFormTemplate as shown below:
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
   { 
     if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
     { 
            GridEditFormItem editItem = (GridEditFormItem)e.Item; 
            DropDownList currency = (DropDownList)editItem.FindControl("DropDownList1"); 
            CheckBox vendor = (CheckBox)editItem.FindControl("CheckBox1"); 
            TextBox bankSequence = (TextBox)editItem.FindControl("TextBox1"); 
            TextBox acountNumber = (TextBox)editItem.FindControl("TextBox2"); 
 
            // similarly you can access other controls 
      } 
   } 

You can also check out the following help document for reference:
Edit forms

Thanks
Princy.
Tags
Grid
Asked by
Adam Hager
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or