Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 15, 2012 11:39 AM by haggis999
Nov 14, 2012 08:10 PM|LINK
I have just created a new web page containing a ListView, which gets its data via a LinqDataSource. When configuring this LinqDataSource, I selected the Advanced option to 'Enable the LinqDataSource to perform automatic updates'. As you can see below, the
LinqDataSource definition includes EnableUpdate = "True".
However, when I subsequently open up the Configure ListView dialogue box the 'Enable Editing' checkbox is both deselected and greyed out. When I view the page in a browser, the data appears correctly but the UpdateButton and CancelButton that are specified
in the EditItemTemplate are not visible and thus no editing is possible.
What am I doing wrong? How do I fully activate the editing option in a ListView?
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="CompDataSQLDataContext" OrderBy="EntryID" Select="new (EntryTitle, Filename)" TableName="Entries" Where="(EntrySummary.EntryFinalised = False) And CompID = 6" EnableUpdate="True">
Nov 14, 2012 10:37 PM|LINK
I've made some progress on this problem. For some obscure reason, Visual Studio created my ListView with both EditIndex and SelectedIndex set to -1 (as shown below). Changing that to a non-negative number made the UpdateButton and CancelButton visible on
the first record. Does anyone know why VS 2010 set these indexes to -1?
<asp:ListView ID="ListView1" runat="server" DataSourceID="LinqDataSource1"
EnableModelValidation="True" EditIndex="-1" SelectedIndex="-1">
Nov 14, 2012 11:25 PM|LINK
My problems are not over.
On reflection (after some browsing elsewhere), I suspect that there should be an
Edit button appearing beside every record, with the Update and
Cancel buttons only appearing for the selected record after an Edit button has been clicked. Is that correct?
As previously stated, I am now seeing an Update button and a Cancel button on just the first record and there is no sign of any Edit buttons. If I make some changes to the selected field and click the Update button, I get the error "LinqDataSource 'LinqDataSource1'
does not support the Select property when the Delete, Insert or Update operations are enabled".
Because of this error I then tried removing the Select statement from my LinqDataSource definition (see my OP) but now when I click on the Update button I get the error "Could not find a row that matches the given keys in the original values stored
in ViewState. Ensure that the 'keys' dictionary contains unique key values that correspond to a row returned from the previous Select operation".
Some further reading suggests that I need to specify something called DataKeyNames for my ListView but it's now after midnight in the UK so that will have to wait until tomorrow...
Nov 15, 2012 09:58 AM|LINK
I think I may have cracked the problem. The ListView automatically does about 95% of the work to generate the required markup via the selections you make in various dialogue boxes but provides no obvious assistance on how to complete the remaining 5%.
In my case, I had to do three things to the automatically generated markup before updating was fully enabled,
I hope this helps other people who have struggled with getting the ListView to work.
Nov 15, 2012 11:39 AM|LINK
Further investigation has established the root cause of my problem.
All my difficulties arose from one thing - my initial selection of specific columns in the LinqDataSource. That is what caused the 'Enable Editing' checkbox to be greyed out and that is what stopped Visual Studio from automatically creating the required
Edit buttons and specifying the appropriate PK in DataKeyNames.
Unfortunately, there seems to be no way to force Visual Studio 2010 to react to a subsequent deletion of the Select statement. The 'Enable Editing' checkbox remains greyed out. You need to wipe out the ListView markup and start again.
However, there is a useful byproduct of this learning experience. By not selecting specific columns you are selecting ALL columns. The standard automatic markup then includes all columns. If you are working with a complex table with many columns, but only
wish to enable the user to view and edit one or two of them, you then have a major task ahead of you to delete a LOT of redundant markup. If you do as I did and start by selecting only the relevant columns and then making the three manual changes listed in
my previous post, you reach the required end result much faster!