• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 738
  • Last Modified:

Object reference not set to an instance of an object.

I have the following scenario. Users can select values from a drop down list and when the selected value changes it triggers the ddlMovement_SelectedIndexChanged. However I am getting the "Object reference not set to an instance of an object." error on line rEShipper.Visible = False. Can someone assist please?

Protected Sub ddlMovement_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ddlMovement As DropDownList = fvShip.FindControl("ddlMovement")
        Dim rEShipper As TableRow = fvShip.FindControl("rEShipper")

              If ddlMovement.SelectedValue = "ADDITIONAL RECOVERY" Then
            rEShipper.Visible = False
                  Else
            rEShipper.Visible = True
                  End If
    End Sub

Open in new window


Which gets triggered by the aspx page:

  <asp:FormView ID="fvShip" runat="server" DataSourceID="sdsShipDetail" CellPadding="0">
                        <EditItemTemplate>
                            <table border="0" id="EditTable">
  <tr>
                                    <td align="left">Type of Movement:</td>
                                    <td align="left"  colspan="4"><asp:DropDownList ID="ddlMovement" SelectedValue='<%# Bind("Movement_Name")%>'  runat="server" DataSourceID="sdsMovement" DataTextField="Movement_Name"
                            DataValueField="Movement_Name" CssClass="form" AutoPostBack="True" OnSelectedIndexChanged="ddlMovement_SelectedIndexChanged">
                        </asp:DropDownList>&nbsp;
                        <asp:SqlDataSource ID="sdsMovement" runat="server" ConnectionString="<%$ ConnectionStrings:BusDevConnectionString %>"
                            SelectCommand="View_Movement_DD_Dell" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
                                    </td>
                                </tr>
<tr>
                                    <td>
                                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" ValidationGroup="PIRUpdate"  
                                            CommandName="Update" Text="Update" ></asp:LinkButton>
                                    </td>
                                    <td  colspan="4">
                                        <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                            Text="Cancel"></asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                            <div>
                            </div>
                        </EditItemTemplate>

Open in new window

0
JessyRobinson1234
Asked:
JessyRobinson1234
1 Solution
 
Atdhe NuhiuCommented:
It would seem that

Dim rEShipper As TableRow = fvShip.FindControl("rEShipper")

is not returning anything. (null)

I can't see a control called rEShipper in the mark up posted
0
 
JessyRobinson1234Author Commented:
Sorry I should have put that in there as well. Here's the aspx code reposted

<asp:FormView ID="fvShip" runat="server" DataSourceID="sdsShipDetail" CellPadding="0">
                        <EditItemTemplate>
                            <table border="0" id="EditTable">
  <tr>
                                    <td align="left">Type of Movement:</td>
                                    <td align="left"  colspan="4"><asp:DropDownList ID="ddlMovement" SelectedValue='<%# Bind("Movement_Name")%>'  runat="server" DataSourceID="sdsMovement" DataTextField="Movement_Name"
                            DataValueField="Movement_Name" CssClass="form" AutoPostBack="True" OnSelectedIndexChanged="ddlMovement_SelectedIndexChanged">
                        </asp:DropDownList>&nbsp;
                        <asp:SqlDataSource ID="sdsMovement" runat="server" ConnectionString="<%$ ConnectionStrings:BusDevConnectionString %>"
                            SelectCommand="View_Movement_DD_Dell" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
                                    </td>
                                </tr>
  <tr id="reShipper">
                                    <td align="left">Shipper Nbr / Return to Plant / Sort / IP:</td>
                                    <td align="left"  colspan="4"><asp:TextBox ID="txtShipper" runat="server" CssClass="form" Width="200px" Text='<%# Bind("Ship_Nbr") %>'></asp:textbox>
                                    </td>
                                </tr>
<tr>
                                    <td>
                                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" ValidationGroup="PIRUpdate"  
                                            CommandName="Update" Text="Update" ></asp:LinkButton>
                                    </td>
                                    <td  colspan="4">
                                        <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                            Text="Cancel"></asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                            <div>
                            </div>
                        </EditItemTemplate> 

Open in new window

0
 
WiesjeCommented:
I would assume it has to do with the fact that in the aspx code it is called reShipper as ID, but in  your code you are looking for rEShipper.
0
 
JessyRobinson1234Author Commented:
I changed it to be rEShipper but same error...
0
 
Alan WarrenApplications DeveloperCommented:
The html table row  <tr id="reShipper"> is not an asp .net control.
Using findcontrol may not be an option.

If you converted the html table to an asp:table, with a runat='server' attribute, you should have more success and should be able to reference the tablerow using:
    ' asp:table e.g.
    <asp:Table ID="thetable" runat="server" >
      <asp:TableRow ID="therow" runat="server">
        <asp:TableCell ID="thecell" runat="server" Text="sometext"></asp:TableCell> 
      </asp:TableRow>
    </asp:Table>

    Dim objrEShipper As TableRow = Nothing
    objrEShipper = CType(Me.fvShip.FindControl("reShipper"), TableRow) ' case matters too

    If objrEShipper IsNot Nothing Then
      With objrEShipper
        If ddlMovement.SelectedValue = "ADDITIONAL RECOVERY" Then
          .Visible = False
        Else
          .Visible = True
        End If
        .Dispose()
      End With
    End If

Open in new window

Alan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now