DataSource problem

S

shapper

Hello,

I am creating, at runtime, a ListView with a LinqDataSource.

I am able to display the data but when I try to delete a record I get
the following error:

"Row not found or changed."

Here is my code (ldsTags is the LinqDataSource and lvTags is the
ListView):

Private Sub ldsTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles ldsTags.Init
With ldsTags
.ContextTypeName = "MyDatabaseDataContext"
.EnableDelete = True
.EnableInsert = True
.EnableUpdate = True
.ID = "ldsTags"
.TableName = "Tags"
End With
End Sub ' ldsTags_Init

Private Sub ldsTags_Selecting(ByVal sender As Object, ByVal e As
LinqDataSourceSelectEventArgs) Handles ldsTags.Selecting

Dim database As New MyDatabaseDataContext
Dim tags = From t In database.Tags _
Select t.TagID, _
t.Text, _
Active = t.FilesTags.Any Or t.ArticlesTags.Any
e.Result = tags

End Sub ' ldsTags_Selecting

Private Sub lvTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles lvTags.Init

With lvTags
.DataKeyNames = New String() {"TagID"}
.DataSourceID = "ldsTags"
.EditItemTemplate = New
ListViewLabTemplate(TemplateType.EditItemTemplate)
.ID = "lvTags"
.ItemTemplate = New
ListViewLabTemplate(TemplateType.ItemTemplate)
.LayoutTemplate = New
ListViewLabTemplate(TemplateType.LayoutTemplate)
End With

End Sub ' lvTags_Init

Private Sub lvTags_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles lvTags.Load
lvTags.DataBind()
End Sub ' lvTags_Load

What am I missing?

Thanks,

Miguel
 
S

shapper

Hello,

I am creating, at runtime, a ListView with a LinqDataSource.

I am able to display thedatabut when I try to delete a record I get
the following error:

"Row not found or changed."

Here is my code (ldsTags is the LinqDataSource and lvTags is the
ListView):

Private Sub ldsTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles ldsTags.Init
With ldsTags
.ContextTypeName = "MyDatabaseDataContext"
.EnableDelete = True
.EnableInsert = True
.EnableUpdate = True
.ID = "ldsTags"
.TableName = "Tags"
End With
End Sub ' ldsTags_Init

Private Sub ldsTags_Selecting(ByVal sender As Object, ByVal e As
LinqDataSourceSelectEventArgs) Handles ldsTags.Selecting

Dim database As New MyDatabaseDataContext
Dim tags = From t In database.Tags _
Select t.TagID, _
t.Text, _
Active = t.FilesTags.Any Or t.ArticlesTags.Any
e.Result = tags

End Sub ' ldsTags_Selecting

Private Sub lvTags_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles lvTags.Init

With lvTags
.DataKeyNames = New String() {"TagID"}
.DataSourceID = "ldsTags"
.EditItemTemplate = New
ListViewLabTemplate(TemplateType.EditItemTemplate)
.ID = "lvTags"
.ItemTemplate = New
ListViewLabTemplate(TemplateType.ItemTemplate)
.LayoutTemplate = New
ListViewLabTemplate(TemplateType.LayoutTemplate)
End With

End Sub ' lvTags_Init

Private Sub lvTags_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles lvTags.Load
lvTags.DataBind()
End Sub ' lvTags_Load

What am I missing?

Thanks,

Miguel

Hi,

To check my Linq classes I created a testing page where the ListView,
LinqDataSource and DataPager were create in DesignView. And it WORKS!

I just can't understand what I am doing wrong when I create this in
Runtime. Could someone please help me out?

I am posting the entire generated code of the page creating using
Design View.

Thank You!

Miguel

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="ListViewDesign.aspx.vb" Inherits="ListViewDesign" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListView ID="ListView1" runat="server"
DataSourceID="LinqDataSource1"
DataKeyNames="TagID" InsertItemPosition="FirstItem">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="TextLabel" runat="server" Text='<%#
Eval("Text") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server"
border="0"
style="">
<tr runat="server" style="">
<th runat="server">
Text</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server"
style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button"
ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server"
CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server"
CommandName="Cancel"
Text="Clear" />
</td>
<td>
<asp:TextBox ID="TextTextBox" runat="server" Text='<%#
Bind("Text") %>' />
</td>
</tr>
</InsertItemTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Label ID="TextLabel" runat="server" Text='<%#
Eval("Text") %>' />
</td>
</tr>
</SelectedItemTemplate>
<EmptyDataTemplate>
<table runat="server"
style="">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server"
CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server"
CommandName="Cancel"
Text="Cancel" />
</td>
<td>
<asp:TextBox ID="TextTextBox" runat="server" Text='<%#
Bind("Text") %>' />
</td>
</tr>
</EditItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Label ID="TextLabel" runat="server" Text='<%#
Eval("Text") %>' />
</td>
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text="Edit"
CommandName="Edit" />
<asp:LinkButton ID="DeleteButton" runat="Server"
Text="Delete" CommandName="Delete" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="Code.Data.Linq.CodeDataContext"
TableName="Tags"
EnableDelete="True" EnableInsert="True" EnableUpdate="True" >
<WhereParameters>
<asp:QueryStringParameter DefaultValue=""1"" Name="TagID"
QueryStringField="id" Type="Object" />
</WhereParameters>
</asp:LinqDataSource>
</div>
</form>
</body>
</html>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top