Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 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 September 13th, 2006, 06:28 AM
Registered User
 
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 10 User Control Problem

Hi,

For some reason the Repeater sql query does not seem to be responding after

   SqlDataSource1.SelectCommand = sel;

It seems as if the select command is empty, however the debugger shows otherwise.

It seems to display data when the sql query is written into

  <asp:SqlDataSource SelectCommand="SELECT * FROM NEWS"

tag.

I have written the code as in the book and connected it with the OnPreRender event of the repeater object and it simply refuses to return anything. I have tried the sql statement on sql server 2005 and it does return the specified number of records so it's not a problem with the query itself.

If there are some steps missing, please let everyone know of the changes that need to be made.
 
Old October 3rd, 2006, 03:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 105
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to DanM
Default

Hi there,
It sounds like you're having the same problems as RobC did in this thread - http://p2p.wrox.com/topic.asp?TOPIC_ID=49117. However, if it's not the same problem, can you please reply and let me know whether you're looking at the C# or VB edition of the book and what page and we'll go from there.

Thanks, Dan

Dan Maharry
Read the feed at http://feeds.feedburner.com/dansarchive
 
Old October 6th, 2006, 09:04 AM
Registered User
 
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Dan,

It is not the same problem as RobC, the connection strings are not at fault here.

I'm looking at the c# version of the book and its the "try it out" starting at page 375.

Cheers
 
Old October 10th, 2006, 07:12 AM
Registered User
 
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As I mentioned above it displays the data when I put the query into

<asp:SqlDataSource

tag.

However, if I try to use the PreRenderer code at Step 8 the sql command simply would not work.
 
Old October 13th, 2006, 10:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 105
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to DanM
Default

Hello again,

I've been trying to get this to not work as you describe it but I can't. The only problem I can find with the Try It Out is getting the control to connect to the database correctly. Hence my query about the connection string.

Out of curiosity, try creating a new data connection for the sqldatasource you create in step 3 using the smart control panel that points to the wroxunited.mdf database. Select any fields from any table you like, test it and close. Then switch to source view and delete the selectcommand=" ... " section from the <asp:SqlDataSource> control tag and continue the example, ignoring step 6. It should work after that.

For reference, here is the working code I have for NewsUserControl.ascx.cs.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class NewsUserControl : System.Web.UI.UserControl
{
    private int _itemsToShow = 5;
    public int ItemsToShow
    {
        get { return _itemsToShow; }
        set { _itemsToShow = value; }
    }

    private void Page_PreRender(object sender, System.EventArgs e)
    {
        string sel = string.Format("select top {0} * FROM [News] WHERE DateToShow <= '{1}' ORDER BY DateToShow DESC",
            _itemsToShow, DateTime.Now.ToString("yyyy/MM/dd"));

        SqlDataSource1.SelectCommand = sel;
    }
}

The Page_PreRender should NOT be connected to the OnPreRender event of the Repeater control - it will be automatically attached to the Page object itself.
 
Old October 16th, 2006, 06:24 AM
Registered User
 
Join Date: Sep 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

LOL... Yes Dan you are correct. The problem was one I created myself! Instead of "Page_PreRender" I had "Page_PreRenderer", the extra 'er' at the end seems to be the culprit.





Similar Threads
Thread Thread Starter Forum Replies Last Post
C# Ch 10 Page 370 - Simple User Control surefire BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 4 February 25th, 2008 01:53 PM
Chapter 10 Treeview Control adonnaru BOOK: Access 2003 VBA Programmer's Reference 1 September 19th, 2006 01:04 PM
Chapter 10 problem rstoos Beginning PHP 1 September 16th, 2006 01:14 PM





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