FindControl Not Finding

2 posts, 0 answers
  1. Rhys
    Rhys avatar
    5 posts
    Member since:
    Jun 2010

    Posted 22 Jun 2010 Link to this post

    Hello All,

     I have a DropDown box inside a FormView, I have and even fireing on the selected index changed, but when I try and assigning the selected value or selected item of the DropDownList to a variable I get the great error “Object reference not set to an instance of an object.”

     

    My Code is attached

     

    Form

     

        <table style="width: 100%;">  
            <tr> 
                <td> 
                    <telerik:RadGrid ID="StockAdjustmentsRadGrid" runat="server"   
                                     AllowPaging="True"   
                                     AllowSorting="True"   
                                     GridLines="None"   
                                     DataSourceID="objDsGetAllAdjustments">  
                        <MasterTableView AutoGenerateColumns="False" DataKeyNames="StockAdjustmentId" DataSourceID="objDsGetAllAdjustments">  
                            <Columns> 
                                <telerik:GridBoundColumn DataField="StockAdjustmentId" DataType="System.Int32" HeaderText="Stock Adjustment Id" ReadOnly="True" SortExpression="StockAdjustmentId" UniqueName="StockAdjustmentId" /> 
                                <telerik:GridBoundColumn DataField="ItemCode" HeaderText="Item Code" ReadOnly="True" SortExpression="ItemCode" UniqueName="ItemCode" /> 
                                <telerik:GridBoundColumn DataField="PrintRoomName" HeaderText="Print Room" ReadOnly="True" SortExpression="PrintRoomName" UniqueName="PrintRoomName" /> 
                                <telerik:GridBoundColumn DataField="Date" DataType="System.DateTime" HeaderText="Date" SortExpression="Date" UniqueName="Date" /> 
                                <telerik:GridBoundColumn DataField="AdjustmentAmount" DataType="System.Decimal" HeaderText="AdjustmentAmount" SortExpression="AdjustmentAmount" UniqueName="AdjustmentAmount" /> 
                                <telerik:GridBoundColumn DataField="AdjustmentReason" HeaderText="AdjustmentReason" SortExpression="AdjustmentReason" UniqueName="AdjustmentReason" /> 
                            </Columns> 
                        </MasterTableView> 
                        <ClientSettings> 
                            <Selecting AllowRowSelect="True" /> 
                        </ClientSettings> 
                    </telerik:RadGrid> 
                </td> 
            </tr> 
            <tr> 
                <td> 
                    <asp:FormView ID="StockAdjustmentFormView" runat="server"   
                                  DataKeyNames="StockAdjustmentId"   
                                  DataSourceID="objDsStockAdjustment"   
                                  DefaultMode="Insert" 
                                  Width="960px">  
                        <InsertItemTemplate> 
                            <table style="width: 100%;">  
                                <tr> 
                                    <td class="MasterFilesLableCells"><asp:Label ID="ItemCodeLabel" runat="server" meta:resourcekey="ItemCodeLabel" /></td>  
                                    <td class="MasterFilesDataCells">  
                                        <telerik:RadComboBox ID="ItemCodeRadComboBox" Runat="server"   
                                                             DataSourceID="objDsItemNames"   
                                                             DataTextField="ItemCode"   
                                                             DataValueField="ItemId"   
                                                             AppendDataBoundItems="True" 
                                                             OnSelectedIndexChanged="ItemCodeRadComboBox_SelectedIndexChanged"   
                                                             AutoPostBack="True"   
                                                             CausesValidation="False">     
                                            <Items> 
                                                <telerik:RadComboBoxItem runat="server" Selected="True" text="Select An Item" Value="-1" /> 
                                            </Items> 
                                        </telerik:RadComboBox> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td class="MasterFilesLableCells"><asp:Label ID="PrintroomNamesLabel" runat="server" meta:resourcekey="PrintroomNamesLabel" /></td>  
                                    <td class="MasterFilesDataCells"><uc2:PrintroomNames ID="PrintroomNames1" runat="server" SelectedValue='<%# Bind("PrintRoomName") %>'  /></td>  
                                </tr> 
                                <tr> 
                                    <td class="MasterFilesLableCells"><asp:Label ID="ItemCostLabel" runat="server" meta:resourcekey="ItemCostLabel" /></td>  
                                      
                                    <td class="MasterFilesDataCells">  
                                        <asp:Label ID="LabelItemCost" runat="server" Text='<%# Bind("ItemCost") %>' /> 
                                    </td> 
                                </tr> 
                                 <tr> 
                                    <td colspan="2">  
                                        <asp:RadioButton ID="RadioButtonAdjustUp" runat="server" Text="Adjust Up" GroupName="AdjustDirection" Checked='<%# Bind("AdjustDirectionUp") %>' /> 
                                        <asp:RadioButton ID="RadioButtonAdjustDown" runat="server" Text="Adjust Down" GroupName="AdjustDirection" Checked='<%# Bind("AdjustDirectionDown") %>' /> 
                                     </td> 
                                </tr> 
                                <tr> 
                                     <td class="MasterFilesLableCells"><asp:Label ID="AdjustmentAmountLabel" runat="server" meta:resourcekey="AdjustmentAmountLabel" /></td>  
                                    <td><telerik:RadTextBox ID="AdjustmentAmountTextBox" runat="server" Text='<%# Bind("AdjustmentAmount") %>'  Skin="Windows7" /></td>  
                                </tr> 
                                <tr> 
                                    <td class="MasterFilesLableCells"><asp:Label ID="AdjustmentDateLabel" runat="server" meta:resourcekey="AdjustmentDateLabel" /></td>  
                                    <td class="MasterFilesDataCells">  
                                        <telerik:RadDatePicker ID="AdjustmentDateLabelRadDatePicker" runat="server" SelectedDate='<%# Bind("AdjustmentDate") %>' > 
                                        </telerik:RadDatePicker> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td colspan="2"><asp:Label ID="AdjustmentReasonLabel" runat="server" meta:resourcekey="AdjustmentReasonLabel" /></td>  
                                </tr> 
                                <tr> 
                                    <td colspan="2">  
                                        <telerik:RadTextBox ID="AdjustmentReasonTextBox" runat="server" Text='<%# Bind("AdjustmentReason") %>' Rows="5" Width="450" Height="50" TextMode="MultiLine" /> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td><asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" /></td>  
                                    <td align="right"><asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /></td>  
                                </tr> 
                            </table> 
                        </InsertItemTemplate> 
                        <ItemTemplate> 
                            <table style="width: 100%;">  
                                <tr> 
                                    <td class="MasterFilesLableCells"><asp:Label ID="ItemCodeLabel" runat="server" meta:resourcekey="ItemCodeLabel" /></td>  
                                    <td class="MasterFilesDataCells"><asp:Label ID="ItemNames1" runat="server" text='<%# Bind("ItemName") %>' /></td>  
                                </tr> 
                                <tr> 
                                    <td class="MasterFilesLableCells"><asp:Label ID="PrintroomNamesLabel" runat="server" meta:resourcekey="PrintroomNamesLabel" /></td>  
                                    <td class="MasterFilesDataCells"><asp:Label ID="PrintroomNames1" runat="server" text='<%# Bind("PrintName") %>' /></td>  
                                </tr> 
                                <tr> 
                                    <td class="MasterFilesLableCells"><asp:Label ID="ItemCostLabel" runat="server" meta:resourcekey="ItemCostLabel" /></td>  
                                    <td class="MasterFilesDataCells"><asp:Label ID="Label1" runat="server" Text='<%# Bind("ItemCost") %>' /></td>  
                                </tr> 
                                 <tr> 
                                    <td colspan="2">  
                                        <asp:RadioButton ID="RadioButtonAdjustUp" runat="server" Text="Adjust Up" Enabled="false" GroupName="AdjustDirection" Checked='<%# Bind("AdjustDirectionUp") %>' /> 
                                        <asp:RadioButton ID="RadioButtonAdjustDown" runat="server" Text="Adjust Down" Enabled="false" GroupName="AdjustDirection" Checked='<%# Bind("AdjustDirectionDown") %>' /> 
                                     </td> 
                                </tr> 
                                <tr> 
                                     <td class="MasterFilesLableCells"><asp:Label ID="AdjustmentAmountLabel" runat="server" meta:resourcekey="AdjustmentAmountLabel" /></td>  
                                    <td><telerik:RadTextBox ID="AdjustmentAmountTextBox" Enabled="false" runat="server" Text='<%# Bind("AdjustmentAmount") %>'  Skin="Windows7" /></td>  
                                </tr> 
                                <tr> 
                                    <td class="MasterFilesLableCells"><asp:Label ID="AdjustmentDateLabel" runat="server" meta:resourcekey="AdjustmentDateLabel" /></td>  
                                    <td class="MasterFilesDataCells"><telerik:RadDatePicker Enabled="false" ID="AdjustmentDateLabelRadDatePicker" runat="server" Skin="Windows7" SelectedDate='<%# Bind("AdjustmentDate") %>' /></td>  
                                </tr> 
                                <tr> 
                                    <td colspan="2" class="MasterFilesLableCells"><asp:Label ID="AdjustmentReasonLabel" runat="server" meta:resourcekey="AdjustmentReasonLabel" /></td>  
                                </tr> 
                                <tr> 
                                    <td colspan="2" class="MasterFilesDataCells">  
                                        <telerik:RadTextBox ID="AdjustmentReasonTextBox" runat="server" Text='<%# Bind("AdjustmentReason") %>'  Skin="Windows7" Rows="5" Width="450" Height="50" TextMode="MultiLine" /> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td><asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" /></td>  
                                    <td align="right"><asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /></td>  
                                </tr> 
                            </table> 
                        </ItemTemplate> 
                    </asp:FormView> 
     
                </td> 
            </tr> 
        </table> 

    Code Behind

     

    Imports SBIS.FMSuite.Items.ItemMasterDAL  
    Partial Public Class StockAdjustment  
     
        Inherits System.Web.UI.Page  
     
     
        Protected Sub ItemCodeRadComboBox_SelectedIndexChanged(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)  
            Dim ItemId As String 
            Dim ItemCodeRadComboBox As Telerik.Web.UI.RadComboBox = CType(FindControl("ItemCodeRadComboBox"), Telerik.Web.UI.RadComboBox)  
            Dim LabelItemCost As Label = CType(FindControl("LabelItemCost"), Label)  
     
            If ItemCodeRadComboBox.SelectedValue.ToString IsNot Nothing Then 
                ItemId = ItemCodeRadComboBox.SelectedValue  
            Else 
                ItemId = 560  
            End If 
     
            Dim ItemsAPI As New SBIS.FMSuite.Items.ItemMasterBLL  
            Dim Items As ItemsDataTable = ItemsAPI.GetItemsByItemID(ItemId)  
            Dim Item As SBIS.FMSuite.Items.ItemMasterDAL.ItemsRow = Items(0)  
            Try 
                If Item.CostingMethod = "Last cost price" Then 
                    LabelItemCost.Text = Item.LastCostPrice  
                Else 
                    LabelItemCost.Text = Item.AverageCostPrice  
                End If 
            Catch ex As Exception  
                LabelItemCost.Text = ex.Message.ToString  
            End Try 
     
        End Sub 
     
    End Class 

    Thank you in advance

  2. Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 25 Jun 2010 Link to this post

    Hello Rhys,

    The problem is that you are trying to find the RadComboBox in the Page. You should fin the FormView first and then the RadComboBox inside:

    Dim combo As RadComboBox = DirectCast(FormView1.FindControl("RadComboBox1"), RadComboBox)

    Hope this helps.

    All the best,
    Veronica Milcheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top