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 May 25th, 2006, 10:52 AM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic data in Gridview

Hi,

I want to return data in a Gridview based on the value of a calculation done elsewhere in the code (stored in a variable and displayed in a Label control). This value should be used to change the products returned e.g.

SELECT products FROM products WHERE watts >= (value of variable).

Can somone explain how I do that? Do I set this in my ObjectDataSource or in some code behind the gridview?

Many thanks,

lukemack.

 
Old May 25th, 2006, 10:14 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You have to change the select command of the datasource:
SqlDataSource1.SelectCommand = "your sql statement"


 
Old May 26th, 2006, 01:52 AM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you mean add that in the dataset code?

What about using filterexpression and filter parameters?

http://msdn2.microsoft.com/en-us/li...parameters.aspx

I tried that but couldnt seem to get it working.



 
Old May 26th, 2006, 03:37 AM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'm actually using an ObjectDataSource. the sql command in the code is as follows:

 <SelectCommand>
                  <DbCommand CommandType="Text" ModifiedByUser="True">
                    <CommandText>SELECT product_name, image_url, watts FROM bo.products</CommandText>
                    <Parameters></Parameters>
                  </DbCommand>
                </SelectCommand>

Does anyone know the syntax for adding a parameter?

 
Old May 26th, 2006, 08:53 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You should get an intro book to asp.net 2.0. Also, there are plenty of exampls in VSHelp and searching online.

 
Old May 26th, 2006, 09:00 AM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks - I've already got an intro book. Thats why I'm at the Wrox forum. I fixed it myself anyway but don't much feel like sharing the knowledge now.
 
Old May 26th, 2006, 03:10 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:but don't much feel like sharing the knowledge now.
Can I ask why not??

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old May 26th, 2006, 03:28 PM
Registered User
 
Join Date: May 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry - was just pretty cheesed off that someone had taken the trouble to basically post 'RTFM'. As a beginner trying to get to grips with ASP.NET 2 in a hurry for a real-life project, thats not what you want to hear.

i decided to use the sqldatasource control as that seemed easier to use and i was able to add a control parameter successfully.

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HBConnectionString %>"
                        SelectCommand="SELECT [product_name], [image_url], [watts] FROM [products] WHERE ([watts] &gt;= @watts) AND [Office]='1' AND [Section]='cooling'">
                                                <SelectParameters>
                            <asp:ControlParameter Name="watts" ControlID="wattsLabel" PropertyName="Text" Type="String" />
                        </SelectParameters>
                    </asp:SqlDataSource>
 
Old May 26th, 2006, 03:37 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Haha, I see.

Anyway, you can parameters to the ObjectDataSource control as well. Just define them on a method in your App_Code folder (or anywhere else).

Then, when you run through the ODS wizard, you get a chance to set up the parameters for the SELECT method. You can then indicate where the params come from (QueryString, Session state and so on).

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic changing value of a gridview button text elwappo ASP.NET 2.0 Professional 6 January 7th, 2008 07:39 AM
Dynamic textbox generation into gridview dharmeshtandel ASP.NET 2.0 Basics 3 December 24th, 2007 02:14 AM
help writing dynamic form data to dynamic table ublend SQL Server ASP 1 June 1st, 2007 08:09 AM
help writing dynamic form data to dynamic table ublend Classic ASP Professional 1 June 1st, 2007 08:08 AM
How to print from a dynamic gridview at runtime. VictorVictor ASP.NET 2.0 Professional 0 April 2nd, 2007 02:19 PM





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