Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5.1 > BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 27th, 2015, 11:52 AM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 13: Using the GridView and SqlDataSource Controls

Hi Imar,

I backtracked to Chapter 13 and found an error that creeped into the Review.aspx code: Error Creating Control - SqlDataSource2. The end tag is missing for <asp:SqlDataSource ID="SqlDataSource2"...

Here is my code.
Code:
<%@ Page Title="Planet Wrox - Management - Reviews" Language="C#" MasterPageFile="~/MasterPages/Management.master" 
  AutoEventWireup="true" CodeFile="Reviews.aspx.cs" Inherits="Management_Review" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
  <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True" AutoPostBack="True" 
    DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Id">
    <asp:ListItem Value="" >Make a selection</asp:ListItem>
  </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>"
    SelectCommand="SELECT [Id], [Name] FROM [Genre]   ORDER BY [SortOrder]" ></asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource2">
        <Columns>
          <asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="AddEditReview.aspx?Id={0}" 
            DataTextField="Title" HeaderText="Title" />
      <asp:TemplateField HeaderText="Authorized" SortExpression="Authorized">
         <ItemTemplate>
            <asp:Label ID="AuthorizedLabel1" runat="server" Text='<%# GetBooleanText(Eval("Authorized")) %>'></asp:Label>
        </ItemTemplate>
      </asp:TemplateField>
      <asp:BoundField DataField="CreateDateTime" DataFormatString="{0:g}" HeaderText="CreateDateTime" 
        SortExpression="CreateDateTime" />
      <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
    </Columns>
  </asp:GridView>
  <a href="AddEditReview.aspx">Insert New Review</a>
  <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" 
    DeleteCommand="DELETE FROM [Review] WHERE [Id] = @Id" 
    InsertCommand="INSERT INTO [Review] ([Title], [Authorized], [CreateDateTime]) VALUES (@Title, @Authorized, @CreateDateTime)" 
    SelectCommand="SELECT [Id], [Title], [Authorized], [CreateDateTime] FROM [Review] WHERE ([GenreId] = @GenreId)" 
    UpdateCommand="UPDATE [Review] SET [Title] = @Title, [Authorized] = @Authorized, [CreateDateTime] = @CreateDateTime 
    WHERE [Id] = @Id"><\asp:SqlDataSource>
    <DeleteParameters>
      <asp:Parameter Name="Id" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
      <asp:Parameter Name="Title" Type="String" />
      <asp:Parameter Name="Authorized" Type="Boolean" />
      <asp:Parameter Name="CreateDateTime" Type="DateTime" />
    </InsertParameters>
    <SelectParameters>
      <asp:ControlParameter ControlID="DropDownList1" Name="GenreId" PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
      <asp:Parameter Name="Title" Type="String" />
      <asp:Parameter Name="Authorized" Type="Boolean" />
      <asp:Parameter Name="CreateDateTime" Type="DateTime" />
      <asp:Parameter Name="Id" Type="Int32" />
    </UpdateParameters>
</asp:Content>
I checked my code, and it appears to me that the end tag is there. I also get a green squiggly line under "SqlDataSource" for "SqlDataSource2".
The Following User Says Thank You to phztfte1 For This Useful Post:
 
Old January 14th, 2016, 03:08 AM
Registered User
 
Join Date: Jan 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The master page must have <form runat="server">, all of the other controls & HTML needed, the placeholders, and a closing </form> tag.

The pages using the master cannot have any <form runat="server"> tags at all, and especially not a closing </form> tag.
 
Old January 14th, 2016, 10:43 AM
Authorized User
 
Join Date: Nov 2014
Posts: 91
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 13: Using the GridView and SqlDataSource Controls

Hi AjitKhodke,

The problem was solved by Imar. See resolution to Chapter 13: Applying the Filter. Both post are the same except for the Title change and an editorial correction.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 13 - Genre GridView Antonius Block BOOK: Beginning ASP.NET 4.5 : in C# and VB 1 January 7th, 2014 05:14 PM
Chapter 13: Not seeing "Edit Columns" choice in SmartTasks Panel for Gridview wgrayson BOOK: Beginning ASP.NET 4 : in C# and VB 7 August 27th, 2012 04:30 AM
conn from Gridview to SqldataSource veda Visual Studio 2005 2 July 9th, 2008 11:49 PM
GridView and SqlDataSource Woes machone3720 ASP.NET 2.0 Basics 1 January 16th, 2007 02:11 PM
Chapter 13 - Creating Your Own Custom Controls msjolin BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 February 16th, 2004 09:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.