Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 11:03 AM
Gridview & DetailsView Database Image Issue ayadrocks ASP.NET 2.0 Basics 1 December 27th, 2005 04:50 PM
Button on GridView that goes to DetailsView AndrewD ASP.NET 2.0 Basics 0 November 30th, 2005 10:09 AM
Can't get DetailsView to work with GridView oneworld95 ASP.NET 2.0 Basics 3 July 16th, 2005 07:19 PM



All times are GMT -4. The time now is 03:56 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.