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

FindControl inside templateForm

2 Answers 88 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Murylo
Top achievements
Rank 1
Murylo asked on 30 Mar 2016, 08:45 AM

Hello guys,

My problem is kind complicated, i'm trying to pass a DataSource to an RadComboBox (List<> provided by wcf service)

my problem is, i'm using the automated Insert button from the radgrid and it pop's up the Add new window

Follow the front end code 

<telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound" OnNeedDataSource="RadGrid1_NeedDataSource" OnInsertCommand="RadGrid1_InsertCommand" OnUpdateCommand="RadGrid1_UpdateCommand" ExportSettings-Word-Format="Docx"    AllowAutomaticDeletes="true"   OnDeleteCommand="RadGrid1_DeleteCommand" GroupPanelPosition="Top" AutoGenerateDeleteColumn="True" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" ShowFooter="True" ShowGroupPanel="True" ShowStatusBar="True" Height="543px" ClientSettings-Scrolling-AllowScroll="true" AutoGenerateColumns="False" AutoGenerateEditColumn="True"
                        >
                        <GroupingSettings CollapseAllTooltip="Collapse all groups" />
                        <ExportSettings>
                            <Word Format="Docx" />
                        </ExportSettings>
                        <ClientSettings>
                            <Scrolling AllowScroll="True" />
                            <Selecting  AllowRowSelect="true" EnableDragToSelectRows="true" />
                        </ClientSettings>
                        <MasterTableView AutoGenerateColumns="false" DataKeyNames="ID"  CommandItemDisplay="top"  EditMode="PopUp"  >
                            <Columns>
                                <telerik:GridBoundColumn DataField="ProductID" DataType="System.Int32" FilterControlAltText="Filter ProductID column" HeaderText="ProductID" SortExpression="ProductID" UniqueName="ProductID">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" FilterControlAltText="Filter ID column" HeaderText="ID" SortExpression="ID" UniqueName="ID" ReadOnly="True">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Quantity" DataType="System.Int32" FilterControlAltText="Filter Quantity column" HeaderText="Quantity" SortExpression="Quantity" UniqueName="Quantity">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="EditDate" DataType="System.DateTime" FilterControlAltText="Filter EditDate column" HeaderText="EditDate" SortExpression="EditDate" UniqueName="EditDate">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="ProductName" FilterControlAltText="Filter Product column" HeaderText="Product" SortExpression="ProductName" UniqueName="ProductName">
                                </telerik:GridBoundColumn>
                            </Columns>
                            <EditFormSettings EditFormType="Template" >
                                <FormTemplate>
                                    Product:
                                    <telerik:RadComboBox
                                         ID="ddProductStock"  Runat="server"   AllowCustomText="True"  DataTextField="Product" DataValueField="ID" Filter="Contains" MarkFirstMatch="True" SelectedValue='<%# Bind("ProductID") %>'  >
                                    </telerik:RadComboBox>
 
                                  
 
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddProductStock" ErrorMessage="*Product cannot be empty!" Font-Bold="True" ForeColor="Red"></asp:RequiredFieldValidator>
 
                                    <br />
                                    Quantity:
                                    <telerik:RadNumericTextBox ID="txtQuantityAdd" Runat="server" LabelWidth="64px" Resize="None" Text='<%# Bind("Quantity", "{0:N}") %>' Width="160px" EmptyMessage="Type The Quantity" MinValue="0" MaxValue="99999999">
                                        <NumberFormat GroupSeparator="" DecimalDigits="0" ></NumberFormat>
                                    </telerik:RadNumericTextBox>
                                      
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtQuantityAdd" ErrorMessage="*Quantity cannot be empty!!" Font-Bold="True" ForeColor="Red"></asp:RequiredFieldValidator>
                                      
                                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:FinancialConnectionString %>" SelectCommand="SELECT [ID], [Product], [Description] FROM [AssetsProd]"></asp:SqlDataSource>
                                    <telerik:RadButton ID="btnUpdate" runat="server"  CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' >
                                        <Icon PrimaryIconCssClass="rbAdd" />
                                    </telerik:RadButton>
                                       
                                    <telerik:RadButton ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                                        <Icon PrimaryIconCssClass="rbCancel" />
                                    </telerik:RadButton>
 
                                </FormTemplate>
                            </EditFormSettings>
                            <CommandItemSettings AddNewRecordText="Add Stock" AddNewRecordImageUrl="Resources/add-text-file.png"  ShowExportToWordButton="true"  ExportToCsvImageUrl="Resources/excel-fil.png" ExportToPdfImageUrl="Resources/pdf-file-format-symbol.png" ExportToWordImageUrl="Resources/docx-file-variant.png" ShowExportToCsvButton="true" ShowExportToPdfButton="true"/>
                        </MasterTableView>
 
                        <FilterItemStyle BackColor="#00CC66" />
                    </telerik:RadGrid>

this is an old code witch i;m updating to work on an API witch dont allow direct SQL connection, it must be provided by web service (the List<>)

But, i need to provide this DataSource to this RadComboBox when the Add new button is pressed to load the list of registered products.

I'm not able to do this right know

i already did to the radgrid1,  

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
     {
        
 
         List<ServiceReference2.Stock> NewStock = new List<ServiceReference2.Stock>();
         NewStock = objServiceClientObjClient.SelectStock().ToList();
         RadGrid1.DataSource = NewStock;
 
   
       }

i tried so many things that i found here, but no one was far close to my problem.

 

thank you 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Helen
Telerik team
answered on 04 Apr 2016, 08:35 AM
Hi,

You can try to access the RadComboBox inside FormTemplate from code behind and set its DataSource property from there. 

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem  && e.Item.IsInEditMode)//editform
       {
         GridEditFormItem editItem = (GridEditFormItem)e.Item;
         RadComboBox rdcombo = (RadComboBox)editItem.FindControl("ddProductStock");
         rdcombo.DataSource=//Set your datasource here.
         rdcombo.DataTextField=//set the DataTextField
         rdcombo.DataValueField=//set the DataValueField
         rdcombo.DataBind();
       }
    }


Regards,
Helen
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Murylo
Top achievements
Rank 1
answered on 06 Apr 2016, 09:19 AM

Hi Helen, i think i forgot to mention, the Datasource is an webservice who return a list, i found in documentation that is not supported at this moment. thanks, i went to another solution

 

 

Tags
ComboBox
Asked by
Murylo
Top achievements
Rank 1
Answers by
Helen
Telerik team
Murylo
Top achievements
Rank 1
Share this question
or