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 <login name>, 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 />
<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>
<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