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
| FAQ | Members List | 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 Search this Thread Display Modes
  #1 (permalink)  
Old December 28th, 2006, 12:30 PM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default gridview not displaying

hi all

i am trying to display my shopping cart in a grdiview.
i have given all the feilds and set everything for datasource
but i am not getting it displayed

i put an empty data control, and it is displaying that control, when i reach the shopping cart.page

but i checked the sqldatasource, giving in test query, the where parameter values, and it is returning the corresponding data

what can be the reason for this?


hope someone helps me!!!
thanks

Reply With Quote
  #2 (permalink)  
Old December 28th, 2006, 05:34 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Hard to say what's going on without looking at your code.

Can you post the relevant code and describe what it's supposed to do??

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #3 (permalink)  
Old December 29th, 2006, 09:53 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the code in my html is

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XXXXConnectionString %>"
            SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice], [Quantity] FROM [ShoppingCart] WHERE (([CartID] = @CartID) AND ([ProductID] = @ProductID))">
            <SelectParameters>
                <asp:Parameter DefaultValue="session.sessionid" Name="CartID" Type="String" />
                <asp:SessionParameter Name="ProductID" SessionField="ProductID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84"
            BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2"
            DataSourceID="SqlDataSource1" ShowFooter="True" Width="514px">
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <EmptyDataTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("ProductID") %>'></asp:TextBox>
            </EmptyDataTemplate>
            <Columns>
                <asp:BoundField DataField="ProductID" HeaderText="ProductID" SortExpression="ProductID" ReadOnly="True" />
                <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" ReadOnly="True" />
                <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" ReadOnly="True" />
                <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
                <asp:CommandField ShowEditButton="True" />
            </Columns>
        </asp:GridView>

Reply With Quote
  #4 (permalink)  
Old December 29th, 2006, 02:39 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

I think this looks a little weird:

  <asp:Parameter DefaultValue="session.sessionid" Name="CartID" Type="String" />

This param will always get the literal value "session.sessionid" instead of the ID of the current session. So, you're querying for something like this:

SELECT ..... FROM [ShoppingCart] WHERE [CartID] = 'session.sessionid')

which won't return any records.

Are you filling the value for the param in the code behind? Is this code from a book or did you make this up??

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #5 (permalink)  
Old December 29th, 2006, 03:04 PM
Friend of Wrox
 
Join Date: Aug 2006
Location: norcross, Ga, USA.
Posts: 107
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i got this code from some site, which i tried to integrate in my application.
in my application, the value for cartid is given through this session.sessionid.
can u suggest any other option to clear this?

Reply With Quote
  #6 (permalink)  
Old December 30th, 2006, 05:28 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

One easy (but very lazy) way to do this is to sync the SessionID in an actual Session field and then use a SessionParameter as the parameter for the data source control. E.g. put the following in Session_Start:

Session("Id") = Session.SessionID

Then in the data source use this:

<asp:SessionParameter Name="CartID" SessionField="Id" />

This gets the value of a Session field called ID (which has been synced from the Session.SessionID).

Alternatively, you can write a handler for the Selecting command of the data source and then fill the parameter with the value from Session.SessionID.

There's a lot to this kind of programming, so you may need to read up a little about how controls like the GridView and the SqlDataSource work and what they're capable of....

Hope this helps,


Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
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

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
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
Displaying images in gridview using code takwirira ASP.NET 2.0 Basics 2 May 23rd, 2008 06:28 AM
Displaying Image in a gridview cholletivinod ASP.NET 2.0 Basics 0 July 3rd, 2007 12:29 AM
Displaying My Data jamil umar ASP.NET 2.0 Basics 0 June 5th, 2006 09:48 AM
displaying parameter value gerll General .NET 1 June 3rd, 2006 03:32 PM



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


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