Wrox Programmer Forums
|
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 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 28th, 2006, 12:30 PM
Friend of Wrox
 
Join Date: Aug 2006
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

 
Old December 28th, 2006, 05:34 PM
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,

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.
 
Old December 29th, 2006, 09:53 AM
Friend of Wrox
 
Join Date: Aug 2006
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>

 
Old December 29th, 2006, 02:39 PM
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,

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.
 
Old December 29th, 2006, 03:04 PM
Friend of Wrox
 
Join Date: Aug 2006
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?

 
Old December 30th, 2006, 05:28 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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.





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





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