Object reference not set to an instance of an object.

Discussion in '.NET' started by zeroesque, Oct 25, 2006.

  1. zeroesque

    zeroesque

    Joined:
    Oct 24, 2006
    Messages:
    3
    Code:
    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Vehicle Details - MCRWeb" %>
    
    <script runat="server">
    
    	Sub Repeater1_OnItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
    		Dim SqlDataSourceLines As SqlDataSource = CType(e.Item.FindControl("SqlDataSourceLines"), SqlDataSource)
    		SqlDataSourceLines.SelectParameters("repair_id").DefaultValue = "3"
    	End Sub
    	
    </script>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="Contentplaceholder1" Runat="Server">
    
    	<!-- Show the vehicle's repair history -->
    	
    	<asp:repeater id="Repeater1" runat="server" onitemdatabound="Repeater1_OnItemDataBound" 
    			datasourceid="SqlDataSourceRepairs" enableviewstate="False">
    		<headertemplate>
    			<b>Repair History</b>
    			<ul>
    		</headertemplate>
    		<itemtemplate>
    			<li>
    				Rep_ID: <%#Eval("repair_id")%> |
    				Date: <%#Eval("shorty_date")%> |
    				Mileage: <%#Eval("mileage")%> |
    				Shop: <%#Eval("shop")%>
    			</li>
    			<ul>
    				<asp:repeater id="Repeater2" runat="server" datasourceid="SqlDataSourceLines" enableviewstate="False">
    					<headertemplate>
    						<ul>
    					</headertemplate>
    					<itemtemplate>
    						<li>
    							Rep_ID: <%#Eval("repair_id")%> |
    							Desc: <%#Eval("description")%> | 
    							Cost: <%#Eval("cost", "{0:C}")%> |
    						</li>
    					</itemtemplate>
    					<footertemplate>
    						</ul>
    					</footertemplate>
    				</asp:repeater>
    				<asp:sqldatasource id="SqlDataSourceLines" enableviewstate="False"
    						runat="server" 
    						connectionstring="<%$ ConnectionStrings:MCRDBConnectionStringUser %>"
    						selectcommand="SELECT [repair_line_id], [repair_id], [description], [cost] FROM [vehicle_repair_lines] WHERE ([repair_id] = @repair_id) ORDER BY [repair_id]">
    					<selectparameters>
    						<asp:parameter defaultvalue="1" name="repair_id" type="String" />
    					</selectparameters>
    				</asp:sqldatasource>
    			</ul>
    		</itemtemplate>
    		<footertemplate>
    			</ul>
    		</footertemplate>
    	</asp:repeater>
    	<asp:sqldatasource id="SqlDataSourceRepairs" runat="server" connectionstring="<%$ ConnectionStrings:MCRDBConnectionStringUser %>"
    		selectcommand="SELECT [repair_id], [vehicle_id], Convert(varchar,[date],101) 'shorty_date', [mileage], [shop] FROM [vehicle_repairs] WHERE ([vehicle_id] = @vehicle_id) ORDER BY [date] DESC" 
    		enableviewstate="False">
    		<selectparameters>
    			<asp:parameter defaultvalue="1" name="vehicle_id" type="Int32" />
    		</selectparameters>
    	</asp:sqldatasource>
    
    </asp:Content>
    Produces the following error (line 7 highlighted):

    Code:
    Server Error in '/' Application.
    --------------------------------------------------------------------------------
    
    Object reference not set to an instance of an object. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
    
    Source Error: 
    
    
    Line 5:  	Sub Repeater1_OnItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
    Line 6:  		Dim SqlDataSourceLines As SqlDataSource = CType(e.Item.FindControl("SqlDataSourceLines"), SqlDataSource)
    Line 7:  		SqlDataSourceLines.SelectParameters("repair_id").DefaultValue = "3"
    Line 8:  	End Sub
    Line 9:  	
     
    
    Source File: D:\webs\devl\mcrWeb\logistics\vehicle_repairs.aspx    Line: 7 
    
    Stack Trace: 
    
    
    [NullReferenceException: Object reference not set to an instance of an object.]
       ASP.logistics_vehicle_repairs_aspx.Repeater1_OnItemDataBound(Object sender, RepeaterItemEventArgs e) in D:\webs\devl\mcrWeb\logistics\vehicle_repairs.aspx:7
       System.Web.UI.WebControls.Repeater.OnItemDataBound(RepeaterItemEventArgs e) +105
       System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +142
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +334
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +53
       System.Web.UI.WebControls.Repeater.DataBind() +72
       System.Web.UI.WebControls.Repeater.EnsureDataBound() +55
       System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +12
       System.Web.UI.Control.PreRenderRecursiveInternal() +77
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360
    
     
    
    
    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42 
    If I comment-out line 7, the page displays, albeit with the inner repeater stuck on a particular recard (I want to programmatically set the inner repeater's select parameter with the outer repeater's OnItemDataBound...but I can't even set it to a static number because of this error)

    Anyone have any idea? If you can solve this, you are clearly a bad-ass kung-fu master!

    Thanks!
    zeroesque, Oct 25, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parthiv Joshi
    Replies:
    2
    Views:
    674
    Kalyan
    Jul 2, 2004
  2. Suresh Kojhani
    Replies:
    1
    Views:
    2,364
    Anushi
    Jul 29, 2004
  3. Chris Fink
    Replies:
    2
    Views:
    4,066
    David Waz...
    Jul 3, 2003
  4. yysiow
    Replies:
    1
    Views:
    423
    Kevin Spencer
    Jul 12, 2003
  5. nguyentrongkha@gmail.com
    Replies:
    1
    Views:
    468
    Mark Rae [MVP]
    Sep 20, 2007
Loading...

Share This Page