Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : 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 9th, 2011, 07:09 AM
Authorized User
 
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
Default CH13 page 460 - not working!

CH13 page 460

Ive done this before following the book and all went well. I am now doing it with my own design. But I am not getting any table showing on the AddEdit page once a user chooses an option on the page before. For this page I am using the ASPNETDB database to show an Admin user who the users are...

Here is the code for the selection page:

Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Admin_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataSourceID="SqlDataSource1">
    <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="UserName" 
            DataNavigateUrlFormatString="addEditUser.aspx?UserName={0}" 
            DataTextField="UserName" HeaderText="User Name" />
        <asp:BoundField DataField="UserId" HeaderText="User ID" 
            SortExpression="UserId" />
        <asp:BoundField DataField="LastActivityDate" HeaderText="Last Date Active" 
            SortExpression="LastActivityDate" />
        <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    
    
        SelectCommand="SELECT u.UserId, u.UserName, u.LastActivityDate, m.Email FROM vw_aspnet_Users AS u INNER JOIN aspnet_Membership AS m ON u.UserId = m.UserId ORDER BY LastActivityDate DESC">
</asp:SqlDataSource>

</asp:Content>
and the code for the addEdit page:

Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMasterPage.master" AutoEventWireup="true" CodeFile="addEditUser.aspx.cs" Inherits="Admin_addEditUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<h2>Edit the user here!</h2>
    <p>
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
            <Fields>
                <asp:BoundField DataField="UserId" HeaderText="UserId" 
                    SortExpression="UserId" />
                <asp:BoundField DataField="UserName" HeaderText="UserName" 
                    SortExpression="UserName" />
                <asp:BoundField DataField="LastActivityDate" HeaderText="LastActivityDate" 
                    SortExpression="LastActivityDate" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT UserId, UserName, LastActivityDate FROM aspnet_Users WHERE (UserName = @UserName)">
            <SelectParameters>
                <asp:Parameter Name="UserName" />
            </SelectParameters>
        </asp:SqlDataSource>
    </p>
</asp:Content>
And the code behind for the addEdit page:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_addEditUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString.Get("UserName") !=null)
        {
            DetailsView1.DefaultMode = DetailsViewMode.Edit;
        }
    }
}
This is what the browser string looks like:
Code:
http://localhost:49431/clientManagerTest/Admin/addEditUser.aspx?UserName=bbb
Do you know why the addEdit page is blank after selection?
 
Old December 10th, 2011, 04:27 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Maybe you SqlDataSource1 needs a QueryStringParameter rather than a plain Parameter in its SelectParameters?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch13 Page 443 - Step 5 problem ken evans BOOK: Beginning ASP.NET 4 : in C# and VB 11 July 27th, 2011 01:35 PM
Ch13 Page 457 Step 12 ken evans BOOK: Beginning ASP.NET 4 : in C# and VB 1 October 25th, 2010 06:37 AM
Chapter 13, Try It out p.460 Apprentice75 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 July 9th, 2010 12:46 PM
Chapter 13 Try It Out Pg. 460 Broken Images workib BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 September 19th, 2008 10:29 AM
Ch13 Case Study 2 alecwood BOOK: Beginning Access 2003 VBA 0 October 18th, 2007 05:40 AM





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