Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Object reference not set to an instance of an object.

Reply
Thread Tools

Object reference not set to an instance of an object.

 
 
zeroesque zeroesque is offline
Junior Member
Join Date: Oct 2006
Posts: 3
 
      10-25-2006
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Object reference not set to an instance of an object" Weird thing happens with reference a link nguyentrongkha@gmail.com ASP .Net 1 09-20-2007 09:46 PM
Error:Object reference not set to an instance of an object. Suresh Kojhani ASP .Net 1 07-29-2004 12:10 PM
Error !Object reference not set to an instance of an object. !!! Help Parthiv Joshi ASP .Net 2 07-02-2004 10:28 AM
Object reference not set to an instance of an object. yysiow ASP .Net 1 07-12-2003 03:30 PM
Object reference not set to an instance of an object. Chris Fink ASP .Net 2 07-03-2003 06:48 PM



Advertisments