Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

DataSource problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 04 Feb 2008 00:39 GMT
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
shapper - 06 Feb 2008 03:08 GMT
> Hello,
>
[quoted text clipped - 59 lines]
>
> 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>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.