Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
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 29th, 2011, 04:55 PM
Registered User
 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help needed for Modification to AddEditReview.aspx

Hi,

I have question about the addeditreview.aspx page.(A bit modified from the example in book)

I am trying to work with details view, but with a field to upload an image to sql database and then render the same image in the another page using a listview (hooked to a dropdown list).

My constraints are as follows: the person editing the review should be able to insert an image which will go and sit in the review table in a column(poster) with datatype=image.

I have been trying this since 2 days but have been unsuccessful in rendering the image.

I am attaching my modified version of your AddEditReview.aspx. Could please somebody explain:

1. how to upload an image that sits as an in a column in database (directly).
2. How to render that image using dropdownlist. (which is the best control to render - I used listview to render, but there is no paging option in list view).

Thanks in advance!
Pradeep

Code:
<%@ Page Title="Planet Wrox - Management - Insert and Update Reviews" Language="C#" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="true" CodeFile="Copy of AddEditReview.aspx.cs" Inherits="Management_AddEditReview" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server">
   <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px" Width="125px" OnItemInserted="DetailsView1_ItemInserted" OnItemInserting="DetailsView1_ItemInserting" OnItemUpdated="DetailsView1_ItemUpdated" OnItemUpdating="DetailsView1_ItemUpdating">
    <Fields>
      <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
        <asp:TemplateField HeaderText="Title" SortExpression="Title">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="TitleYear" SortExpression="TitleYear">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TitleYear") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TitleYear") %>'></asp:TextBox>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("TitleYear") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Poster" SortExpression="poster">
            <EditItemTemplate>
              <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Poster") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:FileUpload ID="FileUpload1" runat="server" 
                    ImageUrl='<%# Eval("poster") %>' />
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("poster") %>'></asp:Label>
                
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Summary" SortExpression="Summary">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox4" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("Summary") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ErrorMessage="Enter A Summary" ControlToValidate="TextBox4"
                    runat="server" />
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox4" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("Summary") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ErrorMessage="Enter A Summary" ControlToValidate="TextBox4"
                    runat="server" />
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" Text='<%# Bind("Summary") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Body" SortExpression="Body">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox5" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ErrorMessage="Enter A Body" ControlToValidate="TextBox5"
                    runat="server" />
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox5" TextMode="MultiLine" Width="500" Height="100" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ErrorMessage="Enter A Body" ControlToValidate="TextBox5"
                    runat="server" />
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label5" runat="server" Text='<%# Bind("Body") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="GenreId" SortExpression="GenreId">
            <EditItemTemplate>
                 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="GenresDataSource" DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("GenreId") %>'>
          </asp:DropDownList>
            </EditItemTemplate>
            <InsertItemTemplate>
                 <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="GenresDataSource" DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("GenreId") %>'>
          </asp:DropDownList>
            </InsertItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label6" runat="server" Text='<%# Bind("GenreId") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
      <asp:CheckBoxField DataField="Authorised" HeaderText="Authorised" 
            SortExpression="Authorised" />
        <asp:CommandField ShowEditButton="True" ShowInsertButton="True" />
    </Fields>
  </asp:DetailsView>
  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" 
        DeleteCommand="DELETE FROM [Review] WHERE [Id] = @Id" 
        InsertCommand="INSERT INTO [Review] ([Title], [TitleYear], [poster], [Summary], [Body], [GenreId], [Authorised]) VALUES (@Title, @TitleYear, @poster, @Summary, @Body, @GenreId, @Authorised)" 
        SelectCommand="SELECT [Id], [Title], [TitleYear], [poster], [Summary], [Body], [GenreId], [Authorised] FROM [Review] WHERE ([Id] = @Id)" 
        
        UpdateCommand="UPDATE [Review] SET [Title] = @Title, [TitleYear] = @TitleYear, [poster] = @poster, [Summary] = @Summary, [Body] = @Body, [GenreId] = @GenreId, [Authorised] = @Authorised WHERE [Id] = @Id">
    <DeleteParameters>
      <asp:Parameter Name="Id" Type="Int32" />
    </DeleteParameters>
    <InsertParameters>
      <asp:Parameter Name="Title" Type="String" />
      <asp:Parameter Name="TitleYear" Type="String" />
      <asp:Parameter Name="poster" Type="Object" />
      <asp:Parameter Name="Summary" Type="String" />
      <asp:Parameter Name="Body" Type="String" />
      <asp:Parameter Name="GenreId" Type="Int32" />
        <asp:Parameter Name="Authorised" Type="Boolean" />
    </InsertParameters>
    <SelectParameters>
      <asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
      <asp:Parameter Name="Title" Type="String" />
      <asp:Parameter Name="TitleYear" Type="String" />
      <asp:Parameter Name="poster" Type="Object" />
      <asp:Parameter Name="Summary" Type="String" />
      <asp:Parameter Name="Body" Type="String" />
      <asp:Parameter Name="GenreId" Type="Int32" />
      <asp:Parameter Name="Authorised" Type="Boolean" />
        <asp:Parameter Name="Id" Type="Int32" />
    </UpdateParameters>
  </asp:SqlDataSource>
  <asp:SqlDataSource ID="GenresDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:PlanetWroxConnectionString1 %>" SelectCommand="SELECT [Id], [Name] FROM [Genre] ORDER BY [SortOrder]"></asp:SqlDataSource>
</asp:Content>
 
Old December 30th, 2011, 06:49 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,

You may want to take another look at Chapter 14. it shows you how to upload and display images using a ListView. In addition, it shows how to implement paging in a ListView using the DataPager.

Your current setup is not going to work, as .NET has no direct way to store an uploaded images in the database. You need to implement some of this yourself which isn't very easy using a DetailsView. Either use the ListView based approach as shown in my book, or take a look at this article for the dirty details on storing images, or image paths in the database:
http://imar.spaanjaars.com/414/stori...with-aspnet-20
http://imar.spaanjaars.com/556/build...stem-using-net

Cheers,

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
Chapter 12 AddEditReview.aspx dgjim BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 23rd, 2010 12:01 PM
modifying the AddEditReview to include a PhotoAlbum robbaralla BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 December 14th, 2009 11:51 AM
Modification on records.....one by one. akshay_rangar ASP.NET 2.0 Basics 0 January 26th, 2007 12:57 PM
C# Help needed in aspx page savoym ASP.NET 1.0 and 1.1 Basics 3 January 28th, 2005 02:34 PM





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