p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501

Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 16th, 2009, 12:33 PM
Authorized User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
Default About displaying data in datalist

Sir,
I am Using book Beginning ASP.NET 2.0...I am building my own website also...I have completed till chapter 12..now I am working with chapter 13-E-commerce...I am able to execute catalog...which is first try it out...
now I want to use this catalog feature in my website for Shopping cart...I have made a database table having one of the column as PictureURL...and I specified a URL of each pic
which I want to upload...But problem is when I bind the ImageButton to my PictureURL...in browser i am not able to see my pics...all pics are jpg and having size max 12kb...

Please help...I am on last step of website..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old September 16th, 2009, 12:36 PM
Authorized User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
Default

please reply fast..plzzz
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old September 16th, 2009, 12:47 PM
Imar's Avatar
Wrox Author
Points: 33,539, Level: 80
Points: 33,539, Level: 80 Points: 33,539, Level: 80 Points: 33,539, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,227
Thanks: 7
Thanked 202 Times in 200 Posts
Default

I'd say it's fair to give people more than a few minutes to read your message and post a reply. People are here in their own free time helping others; they're not your servant.

That said: you can speed up the process yourself by supplying relevant information and code. There could be a million reasons for this problem. So, tell us

1. What your database looks like

2. How you're binding the ImageButton

3. What the paths of the images in the database are

4. Where you've stored your images.

And so on and so forth. Without this information, you can post a "please reply fast" message every minute without getting a reply at all.....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old September 17th, 2009, 04:26 AM
Authorized User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
Default Sorry..

Respected Imar sir,

I am extremely SORRY for my 'plz reply fast' post...that post came in frustration..frustration of getting being stuck on one error for hours...I don't mean than anybody is servant...you are all genius people..and what we are earning today is because of people like you...and your books, once again extremely sorry...

Actually,I have created database exactly same as in book having feilds
1.ProductID
2.Name
3.Description
4.Price
5.PictureURL

My database named Royal and image folder path is stored at 'E:\Bela_ASP.NET\Royal\ProductImages' in PictureURL I just gave this path with image name like
E:\Bela_ASP.NET\Royal\ProductImages\SportsWatch.jp g

I added a SqlDataSource control and DataList control and attached above table to it , then i replaced PictureURL lable with ImageButton and in ImageButton dataBindings for ImageUrl property I select Custom binding and code is Eval("PictureURL","ProductImages\{0}")
code in aspx is looking like
Code:
 <asp:ImageButton ID="ImageButton1"  runat="server" ImageUrl='<%#Eval("PictureURL","~/ProductImages/{0}") %>'  />
Now when I run the project I am not able to see images but a red cross ...

Sir I found a solution with Bind..I just replace the code
Eval("PictureURL","ProductImages\{0}")
with
Bind("PictureURL","ProductImages\{0}") so in aspx i can see as
Code:
 <asp:ImageButton ID="ImageButton1"  runat="server" ImageUrl='<%#Bind("ImageURL","~/ProductImages/{0}") %>' />
Now I am able to see my pics..but Sir I just want to know is the thing that I have to store image in database??..then only I can use Eval??
and what is exact difference between Eval and Bind??

Once again SoRRy

Last edited by bela_sush : September 17th, 2009 at 04:40 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old September 17th, 2009, 05:36 PM
Imar's Avatar
Wrox Author
Points: 33,539, Level: 80
Points: 33,539, Level: 80 Points: 33,539, Level: 80 Points: 33,539, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,227
Thanks: 7
Thanked 202 Times in 200 Posts
Default

Eval is for one-way binding, Bind for two-way binding. Eval is often used for read-only data while you typically use Bind for editing scenario: http://www.google.com/search?hl=en&s...nd+&aqi=g6g-m1

But are you sure that's the only difference you made? If the database contains a valid picture URL (a relative path, I assume, not something like E:\Bela_ASP.NET\...) then it should display correctly with Eval as well....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old September 18th, 2009, 08:20 AM
Authorized User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
Default Thank you

Respected Imar Sir,

Yes I have done only one change that is instead of Eval I use Bind...Sir..I am almost at end of shopping cart now....actually my shopping cart is running perfectly except one thing...when I added some item into cart..It shows me all relevent details but again a red cross at image feild...

I am going exactly as per book beginning asp.net 2.0...In WroxShopping.ascx my code is looking as follows..
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ShoppingCart.ascx.cs" Inherits="ShoppingCart" %>
<asp:GridView ID="CartGrid" AutoGenerateColumns="False" DataKeyNames="ProductID" runat="server" OnRowCancelingEdit="CartGrid_RowCancelingEdit" OnRowDeleting="CartGrid_RowDeleting" OnRowUpdating="CartGrid_RowUpdating" OnRowEditing="CartGrid_RowEditing">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Image ID="Image1" runat="server" ImageUrl='<%# Bind("ProductImageUrl", "~/ProductImages/{0}") %>' Width="100" />
            </ItemTemplate>
        </asp:TemplateField>
       
      
        <asp:BoundField DataField="ProductName" HeaderText="Product" ReadOnly="True" />
        <asp:BoundField DataField="Quantity" HeaderText="Quantity" />
         <asp:BoundField DataField="Price" HeaderText="Price" ReadOnly="True" DataFormatString="{0:c}" />
         <asp:BoundField DataField="LineTotal" HeaderText="Total" ReadOnly="True" DataFormatString="{0:c}" />


        <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
    </Columns>
    <EmptyDataTemplate>
        There is nothing in your shopping cart. You can buy items from the <a href="Shop.aspx">Shop.</a>
    </EmptyDataTemplate>
</asp:GridView>
<br />
<asp:Label ID="TotalLabel" runat="server"></asp:Label>
I have a imagebutton on another page as 'Add to cart' when I click that button my selected item goes to cart...
code for imagebutton is
Code:
 protected void btnAddToCart_Click(object sender, ImageClickEventArgs e)
    {
        double Price = double.Parse(((Label)DataList1.Controls[0].FindControl("PriceLabel")).Text);
        string ProductName = ((Label)DataList1.Controls[0].FindControl("NameLabel")).Text;
        string PictureURL = ((Label)DataList1.Controls[0].FindControl("PictureUrlLabel")).Text;
        int ProductID = int.Parse(Request.QueryString["ProductID"]);


        if (Profile.Cart == null)
        {
            Profile.Cart = new Royal.Commerce.RoyalShoppingCart();
        }
        Profile.Cart.Insert(ProductID, Price, 1, ProductName, PictureURL);
        Server.Transfer("Shop.aspx");

    }
but i don't know why, on my shopping cart i found a red cross..
I am able to see images on Catalog, able to see image on selectItem.aspx but
a red cross on this shopping cart.ascx...
I try with both Bind and Eval...also I have provided relative path in database...
what could be the reason for red cross??
Thank you in advance
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old September 19th, 2009, 05:20 AM
Imar's Avatar
Wrox Author
Points: 33,539, Level: 80
Points: 33,539, Level: 80 Points: 33,539, Level: 80 Points: 33,539, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,227
Thanks: 7
Thanked 202 Times in 200 Posts
Default

Quote:
I try with both Bind and Eval...also I have provided relative path in database
Now I am confused. I thought it worked with Bind and not with Eval?

Anyway, take a look at the final HTML in the browser. How do your image path (the src attribute) look? Do they look valid? What happens when you request these paths directly in the browser?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
bela_sush (September 20th, 2009)
  #8 (permalink)  
Old September 20th, 2009, 05:52 AM
Authorized User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
Smile Almost done...

Respected Imar sir,

Thank you for your valuable time and suggestions...Yes I have solved my all problems regarding shopping cart...actually what you said is correct...I made a mistake while giving slash ( / )....But still...Bind is working but not Eval...

I almost done with my shopping cart....and my first web site is in it's final step..

I am thinking for enhancement in project....and may need your help...

Thank you in advance...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old September 23rd, 2009, 06:00 AM
Authorized User
Points: 53, Level: 1
Points: 53, Level: 1 Points: 53, Level: 1 Points: 53, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Posts: 15
Thanks: 4
Thanked 0 Times in 0 Posts
Question Error

Respected Imar sir,
I am sorry because once again this shopping cart is giving me a problem...everything is working fine...people able to view shopping cart, able to add an item to cart, able to edit shopping cart..

But now the problem is in Chechout.aspx form...everything working good in checkout.aspx, but when I click on Finish button and try to enter cart details in database, I get an error as follows:
Code:
  Server Error in '/Royal' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 105:        try
Line 106:        {
Line 107:            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Royal"].ConnectionString);
Line 108:            conn.Open();
Line 109:            trans = conn.BeginTransaction();
 

Source File: e:\Marathi\Royal\Checkout.aspx.cs    Line: 107 

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   Checkout.Wizard1_FinishButtonClick1(Object sender, WizardNavigationEventArgs e) in e:\Marathi\Royal\Checkout.aspx.cs:107
   System.Web.UI.WebControls.Wizard.OnFinishButtonClick(WizardNavigationEventArgs e) +75
   System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +619
   System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +17
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +86
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4921
error is on line no. 107

my code for database connection is as follows
Code:
 protected void Wizard1_FinishButtonClick1(object sender, WizardNavigationEventArgs e)
    {
        // Insert the order and order lines into the database
        SqlConnection conn = null;
        SqlTransaction trans = null;
        SqlCommand cmd;

        try
        {
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Royal"].ConnectionString);
            conn.Open();
            trans = conn.BeginTransaction();

            cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.Transaction = trans;

            // set the order details
            cmd.CommandText = "INSERT INTO Orders(MemberName, OrderDate, Name, Address, County, PostCode, Country, SubTotal, Discount, Total) " + "VALUES (@MemberName, @OrderDate, @Name, @Address, @County, @PostCode, @Country, @SubTotal, @Discount, @Total)";
            cmd.Parameters.Add("@MemberName", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@OrderDate", SqlDbType.DateTime);
            cmd.Parameters.Add("@Name", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@Address", SqlDbType.VarChar, 255);
            cmd.Parameters.Add("@PostalCode", SqlDbType.VarChar, 15);
            cmd.Parameters.Add("@Country", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@SubTotal", SqlDbType.Money);
            cmd.Parameters.Add("@Discount", SqlDbType.Money);
            cmd.Parameters.Add("@Total", SqlDbType.Money);

            cmd.Parameters["@MemberName"].Value = User.Identity.Name;
            cmd.Parameters["@OrderDate"].Value = DateTime.Now;
            cmd.Parameters["@Name"].Value = ((TextBox)Wizard1.FindControl("txtName")).Text;
            cmd.Parameters["@Address"].Value = ((TextBox)Wizard1.FindControl("txtAddress")).Text;
            cmd.Parameters["@PostalCode"].Value = ((TextBox)Wizard1.FindControl("txtPostalCode")).Text;
            cmd.Parameters["@Country"].Value = ((TextBox)Wizard1.FindControl("txtCountry")).Text;
            cmd.Parameters["@Total"].Value = Profile.Cart.Total;

            int OrderID = Convert.ToInt32(cmd.ExecuteScalar());

            // change the query and parameters for the order lines
            cmd.CommandText = "INSERT INTO OrderLines(OrderID, ProductID, Quantity, Price) " +
              "VALUES (@OrderID, @ProductID, @Quantity, @Price)";
            cmd.Parameters.Clear();
            cmd.Parameters.Add("@OrderID", SqlDbType.Int);
            cmd.Parameters.Add("@ProductID", SqlDbType.Int);
            cmd.Parameters.Add("@Quantity", SqlDbType.Int);
            cmd.Parameters.Add("@Price", SqlDbType.Money);

            cmd.Parameters["@OrderID"].Value = OrderID;
            foreach (CartItem item in Profile.Cart.Items)
            {
                cmd.Parameters["@ProductID"].Value = item.ProductID;
                cmd.Parameters["@Quantity"].Value = item.Quantity;
                cmd.Parameters["@Price"].Value = item.Price;

                cmd.ExecuteNonQuery();
            }

            // commit the transaction
            trans.Commit();



        }
        catch (SqlException SqlEx)
        {
            // some form of error - rollback the transaction 
            // and rethrow the exception
            if (trans != null)
                trans.Rollback();



            // Log the exception
            // Tools.log("An error occurred while creating the order", SqlEx)
            throw new Exception("An error occurred while creating the order", SqlEx);
        }
        finally
        {
            if (conn != null)
                conn.Close();
        }

        // we will only reach here if the order has been created sucessfully
        // so clear the cart
        Profile.Cart.Items.Clear();
  
    }
Please help me..
Thank you in advance..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old September 23rd, 2009, 08:11 AM
Imar's Avatar
Wrox Author
Points: 33,539, Level: 80
Points: 33,539, Level: 80 Points: 33,539, Level: 80 Points: 33,539, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,227
Thanks: 7
Thanked 202 Times in 200 Posts
Default

Looks like you don't have a connection string called Royal in your web.config file....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
bela_sush (September 23rd, 2009)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
datalist not displaying... sarah lee ASP.NET 1.0 and 1.1 Basics 1 October 3rd, 2006 11:42 AM
datalist not displaying.. help me please sarah lee ASP.NET 1.0 and 1.1 Basics 10 August 31st, 2006 08:48 AM
Displaying master/detail relationship in datalist cq_ted ASP.NET 1.x and 2.0 Application Design 0 May 10th, 2006 02:07 AM
Displaying multiple dataset tables in a datalist Colonel Angus ASP.NET 1.1 9 May 11th, 2005 02:46 PM
Datalist does not display data sanjeet ADO.NET 1 August 9th, 2003 12:26 AM



All times are GMT -4. The time now is 10:58 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc