Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 April 25th, 2008, 11:34 AM
Authorized User
 
Join Date: Sep 2007
Location: Rugeley, , United Kingdom.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB: GridView & DetailsView in Master-Child

I am using VWD 2005 Express and MS SQL Server 2005 Express.

The purpose of my page is to provide insert and edit of Walking Group activities. The GridView displays a few fields for identification purposes, and four of the records with paging and selection. The DetailsView is supposed to follow the selection and provide a complete list of fields. Edit and Insert are turned on.
The SELECT statement of the DetailsView data source has a WHERE clause:
Code:
WHERE (Events.EventID = @EventID)
But how does this pick up the EventID of the GridView? And why doesn't it work? EventID is included in the SELECT statement of the GridView data source.

Also, there is an ImageURL field in the DetailsView which is a hyperlink to a relevant photo. I would like to enable this string as a hyperlink in the browser, or alternatively display the image. How would I do this?

My aspx source is below.

Code:
<%@ Page Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" CodeFile="Update.aspx.vb" Inherits="admin_Update" title="Event Update for Church Lane Walking Group" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    Good morning/afternoon/evening &lt;login name&gt;, welcome to the update page. Here
    you can enter details of a new event, or modify details already entered, so long
    as the event hasn't happened yet!<br />
    &nbsp;&nbsp;<asp:gridview ID="GridView1" runat="server" AutoGenerateColumns="False"
        DataKeyNames="EventID" DataSourceID="SqlDataSource2" AllowPaging="True" PageSize="4">
        <columns>
            <asp:commandfield ShowSelectButton="True" />
            <asp:boundfield DataField="EventName" HeaderText="Event" />
            <asp:boundfield DataField="EventDescription" HeaderText="Description" />
            <asp:boundfield DataField="StartDate" HeaderText="Date" />
        </columns>
    </asp:gridview>
    <asp:sqldatasource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:UpdateConnectionString1 %>"
        SelectCommand="SELECT [EventName], [Location], [StartDate], [EventDescription], [WalkDistance], [EventID] FROM [Events] ORDER BY [StartDate] DESC" OldValuesParameterFormatString="original_{0}">
    </asp:sqldatasource>
    <br />
            <asp:detailsview ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" DataSourceID="SqlDataSource1" Height="200px" Width="500px" BackColor="#FFFFC0" BorderColor="#FFFFC0" BorderStyle="Dashed" BorderWidth="1px" Caption="Click Edit to change event data, or New to add." CellPadding="5" CellSpacing="2">
                <pagersettings FirstPageText="Earliest" LastPageText="Latest" Mode="NextPreviousFirstLast"
                    NextPageText="Later" PreviousPageText="Earlier" />
                <commandrowstyle BorderColor="White" ForeColor="Maroon" />
                <fieldheaderstyle BorderColor="Maroon" BorderStyle="Solid" BorderWidth="1px" HorizontalAlign="Right" />
                <pagerstyle ForeColor="Maroon" Wrap="True" />
                <fields>
                    <asp:boundfield DataField="EventName" HeaderText="EventName" SortExpression="EventName" />
                    <asp:boundfield DataField="EventDescription" HeaderText="EventDescription" SortExpression="EventDescription" />
                    <asp:boundfield DataField="Location" HeaderText="Location" SortExpression="Location" />
                    <asp:boundfield DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate" />
                    <asp:boundfield DataField="Travel" HeaderText="Travel" SortExpression="Travel" />
                    <asp:boundfield DataField="ImageURL" HeaderText="ImageURL" HtmlEncode="False" NullDisplayText="Sorry, no photo available." />
                    <asp:commandfield ShowEditButton="True" ShowInsertButton="True" />
                </fields>
            </asp:detailsview>
    &nbsp; &nbsp;
    <asp:sqldatasource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:AdminConnectionString %>"
        OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT Events.EventName, Events.Location, Events.StartDate, Events.StartTime, Events.EventDescription, Events.EventID, Travel.Travel, [Group Photos].ImageURL FROM Events INNER JOIN [Group Photos] ON Events.EventID = [Group Photos].EventID INNER JOIN Travel ON Events.EventID = Travel.EventID WHERE (Events.EventID = @EventID)" ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM [Events] WHERE [EventID] = @original_EventID AND [EventName] = @original_EventName AND [Location] = @original_Location AND [StartDate] = @original_StartDate AND [StartTime] = @original_StartTime AND [EventDescription] = @original_EventDescription" InsertCommand="INSERT INTO [Events] ([EventName], [Location], [StartDate], [StartTime], [EventDescription]) VALUES (@EventName, @Location, @StartDate, @StartTime, @EventDescription)" UpdateCommand="UPDATE [Events] SET [EventName] = @EventName, [Location] = @Location, [StartDate] = @StartDate, [StartTime] = @StartTime, [EventDescription] = @EventDescription WHERE [EventID] = @original_EventID AND [EventName] = @original_EventName AND [Location] = @original_Location AND [StartDate] = @original_StartDate AND [StartTime] = @original_StartTime AND [EventDescription] = @original_EventDescription">
        <deleteparameters>
            <asp:parameter Name="original_EventID" Type="Int32" />
            <asp:parameter Name="original_EventName" Type="String" />
            <asp:parameter Name="original_Location" Type="String" />
            <asp:parameter Name="original_StartDate" Type="DateTime" />
            <asp:parameter Name="original_StartTime" Type="DateTime" />
            <asp:parameter Name="original_EventDescription" Type="String" />
        </deleteparameters>
        <updateparameters>
            <asp:parameter Name="EventName" Type="String" />
            <asp:parameter Name="Location" Type="String" />
            <asp:parameter Name="StartDate" Type="DateTime" />
            <asp:parameter Name="StartTime" Type="DateTime" />
            <asp:parameter Name="EventDescription" Type="String" />
            <asp:parameter Name="original_EventID" Type="Int32" />
            <asp:parameter Name="original_EventName" Type="String" />
            <asp:parameter Name="original_Location" Type="String" />
            <asp:parameter Name="original_StartDate" Type="DateTime" />
            <asp:parameter Name="original_StartTime" Type="DateTime" />
            <asp:parameter Name="original_EventDescription" Type="String" />
        </updateparameters>
        <insertparameters>
            <asp:parameter Name="EventName" Type="String" />
            <asp:parameter Name="Location" Type="String" />
            <asp:parameter Name="StartDate" Type="DateTime" />
            <asp:parameter Name="StartTime" Type="DateTime" />
            <asp:parameter Name="EventDescription" Type="String" />
        </insertparameters>
        <selectparameters>
            <asp:controlparameter ControlID="GridView1" Name="EventID" PropertyName="SelectedValue"
                Type="Int32" />
        </selectparameters>
    </asp:sqldatasource>
</asp:Content>
Richard
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express
__________________
Richard
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express
 
Old May 29th, 2008, 07:14 AM
Authorized User
 
Join Date: Sep 2007
Location: Rugeley, , United Kingdom.
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've found what I was looking for. The problem wasn't in the source but in the database. I am combining fields from three tables using EventID as the key.
Unfortunately, two of the tables concerned were under-populated. I added records to them using VWD Database Explorer and the page sprang into life.
Now I can get on and evaluate the rest of the page.

Richard
Rugeley, UK
WinXP Pro SP2
VBW Express + SQL Server 2005 Express




Similar Threads
Thread Thread Starter Forum Replies Last Post
Using DetailsView control to add record to Child megnin ASP.NET 1.x and 2.0 Application Design 0 September 5th, 2008 03:37 PM
VB GridView & DetailsView Rich57 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 February 1st, 2008 12:03 PM
Gridview & DetailsView Database Image Issue ayadrocks ASP.NET 2.0 Basics 1 December 27th, 2005 05:50 PM
Button on GridView that goes to DetailsView AndrewD ASP.NET 2.0 Basics 0 November 30th, 2005 11:09 AM
Can't get DetailsView to work with GridView oneworld95 ASP.NET 2.0 Basics 3 July 16th, 2005 07:19 PM





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