Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASP:Listview and LinqToSQLDataSource Error

Posted on 2009-02-08
6
Medium Priority
?
775 Views
Last Modified: 2013-12-17
Okay, I've had some strange issues using the asp:Listview control and the LinqtoSQL datasource control.

It is binding fine and will show up the items as expected; however, when I try to click an item it will never use the SelectedItemTemplate.  I did some digging and when debugging decided to set the selectedindex manually just to see if I could.  When I do it, it throws an exception saying an object reference not set to an instance of an object.  

Now I feel like this is due to my lack of experience using the declarative datasource objects (before I've done it manually) but I just can't seem to figure out why it won't select an item.

Judging by my stack trace (included) it seems that there may be an issue somewhere with the datasource's setup and perhaps my misunderstanding of the select setup.

I'm going to paste my listview and the datasource as well as the stack trace and would appreciate any help available!

PS: The table is fairly simple it just includes an Id (primary key), Name (varchar(40))
// ASP.Net Code
// -------------------------
<asp:LinqDataSource ID="LINQCategories" runat="server" 
                            ContextTypeName="AIMDB2.AIMdb" TableName="InventoryCats" Select="new (Id, Name)">
                        </asp:LinqDataSource>
 
// ListView
<asp:ListView ID="lvCategories" runat="server" GroupItemCount="6"
                                    DataSourceID="LINQCategories">
	                                    <LayoutTemplate>
		                                    <table id="Table1" runat="server">
			                                    <tr id="Tr1" runat="server">
				                                    <td id="Td1" runat="server">
					                                    <table ID="groupPlaceholderContainer" runat="server">
						                                    <tr runat="server" id="groupPlaceholder" />
					                                    </table>
				                                    </td>
			                                    </tr>
			                                    <tr id="Tr2" runat="server">
				                                    <td id="Td2" runat="server" style="">
				                                    </td>
			                                    </tr>
		                                    </table>
		                                    <asp:DataPager runat="server" ID="DataPager" PageSize="12">
                                                <Fields>
                                                  <asp:NumericPagerField runat="server" ButtonCount="10"
                                                       PreviousPageText="<--"
                                                       NextPageText="-->" />
                                                </Fields>
                                            </asp:DataPager>
	                                    </LayoutTemplate>
	                                    <GroupTemplate>
	                                        <tr runat="server" id="CatagoryItem">
	                                            <td runat="server">
	                                                <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
	                                            </td>
	                                        </tr>
	                                    </GroupTemplate>
	                                    <ItemTemplate>
	                                        <td id="Td1" runat="server" style="font-family:Arial;padding: 5px 5px; font-size:small;" >
	                                            <asp:Image ID="Image1" Width="80" Height="80" runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1" onerror="DisplayDefaultCatalogImage(this)"  ImageUrl='<%#Eval("Id","http://catalog.motionmedical.com/Itemcat/{0}.jpg") %>' style="width:100px"/><br />
	                                            <p style="vertical-align:bottom;"><%#Eval("Name") %></p>
	                                        </td>
	                                    </ItemTemplate>
	                                    <EmptyDataTemplate>
	                                        <td id="Td1" runat="server" style="font-family:Arial;font-size:0.5em;padding: 5px 5px;">
	                                            No Data Available
	                                        </td>
	                                    </EmptyDataTemplate>
	                                    <EmptyItemTemplate>
	                                        <td id="Td1" runat="server">&nbsp;</td>
	                                    </EmptyItemTemplate>
	                                    <SelectedItemTemplate>
	                                        <td id="Td1" runat="server">
	                                            HI
	                                        </td>
	                                    </SelectedItemTemplate>
                                    </asp:ListView>
 
//Stack Trace
//-------------------------
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
 
Stack Trace:
 
[NullReferenceException: Object reference not set to an instance of an object.]
   System.Data.Linq.SqlClient.QueryConverter.VisitInvocation(InvocationExpression invoke) +1503171
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1329
   System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +34
   System.Data.Linq.SqlClient.QueryConverter.VisitBinary(BinaryExpression b) +52
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +591
   System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp) +34
   System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression sequence, LambdaExpression predicate) +145
   System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +3145
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1091
   System.Data.Linq.SqlClient.QueryConverter.VisitSelect(Expression sequence, LambdaExpression selector) +41
   System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +1292
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1091
   System.Data.Linq.SqlClient.QueryConverter.VisitDistinct(Expression sequence) +24
   System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +3687
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1091
   System.Data.Linq.SqlClient.QueryConverter.VisitSelect(Expression sequence, LambdaExpression selector) +41
   System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +1292
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1091
   System.Data.Linq.SqlClient.QueryConverter.VisitAggregate(Expression sequence, LambdaExpression lambda, SqlNodeType aggType, Type returnType) +93
   System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc) +4511
   System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node) +1091
   System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node) +79
   System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations) +211
   System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +149
   System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute(Expression expression) +42
   System.Web.Query.Dynamic.DynamicQueryable.Count(IQueryable source) +209
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelectAutoSortAndPage(IQueryable source, DataSourceSelectArguments arguments) +153
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelectQuery(LinqDataSourceSelectEventArgs selectEventArgs, Object selectResult, Object table, Boolean storeOriginalValues) +745685
   System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +509
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +27
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +261
   System.Web.UI.WebControls.ListView.PerformSelect() +74
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.ListView.CreateChildControls() +74
   System.Web.UI.Control.EnsureChildControls() +146
   System.Web.UI.Control.PreRenderRecursiveInternal() +61
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Control.PreRenderRecursiveInternal() +224
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394

Open in new window

0
Comment
Question by:luscoma
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:Salim Fayad
ID: 23588075
The problem is that you are not "selecting" the item. You are just clicking on it. Add a button and in its "CommandName" put "Select"
0
 

Author Comment

by:luscoma
ID: 23588095
I just tried that, the problem is it postsback like you'd expect but doesn't show the selecteditemtemplate.  I feel like this is due to that exception (which shows up if I add lvCatagories.SelectedIndex = 0 in an ondatabound event).  This makes me believe its not picking up the selecteditemtemplate because of that exception
0
 

Author Comment

by:luscoma
ID: 23588100
Side note if you want to see the current state of it, its at http://www.motionmedical.com/physician/catalog.aspx (its not styled or anything like that just an accordion control with a listview in it)  It doesn't show that exception right now cause I took out the SelectedIndex = 0 part so it would load.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Expert Comment

by:Salim Fayad
ID: 23589007
Here is what you have to do:
1. The select button must be like the following:

<asp:Button ID="btnSelect" runat="server" CommandName="Select" CommandArgument="" />
<?xml:namespace prefix = asp />2. Use the event SelectedIndexChanging of the ListView and implement the following inside it:

    protected void lvCategories_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
    {
        lvCategories.SelectedIndex = e.NewSelectedIndex;
    }

Open in new window

0
 
LVL 11

Accepted Solution

by:
Salim Fayad earned 2000 total points
ID: 23589015
Sorry, the select button must be like the following:
<asp:Button ID="btnSelect" runat="server" CommandName="Select" CommandArgument="" /> 

Open in new window

0
 

Author Comment

by:luscoma
ID: 23591552
You are perhaps my hero....
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question