Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 June 6th, 2013, 06:07 AM
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
Default Filtering data

I would like to filter data using Gridview like the examples on page 446/446. However I am missing the Parameter option in my VWD express. How can I transfer a calculated integer to this Where clause? Currently the only way that I can think of is using a cookie, somehow I think it could be done easier!

Erik
Reply With Quote
  #2 (permalink)  
Old June 6th, 2013, 06:10 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Can you explain what you mean with " I am missing the Parameter option in my VWD express"? Your version should offer the same functionality as mine ;-)

Maybe you can post your working code and explain where the "calculated integer" comes from?

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!
Reply With Quote
  #3 (permalink)  
Old June 6th, 2013, 06:12 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Also, check out this article: http://imar.spaanjaars.com/571/letti...t-45-web-forms

You can do similar stuff with your controls by handling the Selecting event: http://msdn.microsoft.com/en-us/libr...selecting.aspx

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!
Reply With Quote
  #4 (permalink)  
Old June 6th, 2013, 06:26 AM
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
Default Thanks for this prompt reply

Thanks Imar:

When you click Where you get the wizzard for selction: Your book options are:Control, Cookie, Form, Parameter, Profile, Querystring and Session.
My wizzard has Control, Cookie, form, Profile, Query, Session and Route

So I am missing Parameter, which in your book says: you typically set the value through code..... I would like to use RV in my Where SQLDatasource

protected void CBKleur_SelectedIndexChanged(object sender, EventArgs e)
{
Double RV = 0;
for (int i = 1; i < CBKleur.Items.Count; i++)
{
if (CBKleur.Items[i].Selected) { RV += Math.Pow(2, (i - 1)); }
}
}

I will read your other link now :-)

Regards
Erik
Reply With Quote
  #5 (permalink)  
Old June 6th, 2013, 07:36 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Ah, I thought you were using an EntityDataSource control. In that case, the correct link is:

http://msdn.microsoft.com/en-us/libr...selecting.aspx

The "Parameter" type maps to None in the drop down list. When you set up a new parameter and choose None, you get this in the Markup:

<asp:Parameter Name="ColumnName" Type="Int32" />

where ColumnName is the name of the column you associated with the Where clause.

You can then do something like this in the Code Behind (C#):

Code:
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
  e.Command.Parameters["@ColumnName"].Value = YourCalculatedValue;
}
Hope this helps.

Groeten,

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!
Reply With Quote
  #6 (permalink)  
Old June 6th, 2013, 11:15 AM
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
Default half way there

thanks Imar, exactly what I needed. To finalize I am troubled why the value of RV is not transferred in below code between the 2 routines

Code:
public partial class Zoek : System.Web.UI.Page
{
    public Double RV;

    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

 
    protected void CBKleur_SelectedIndexChanged(object sender, EventArgs e)
    {
        // calculate value for where clause
        RV = 0;
        for (int i = 1; i < CBKleur.Items.Count; i++)
        {
            if (CBKleur.Items[i].Selected) { RV += Math.Pow(2, (i - 1)); }
        }
    }

    protected void SqlDataSource11_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        
        Int32 ColorSelected = Convert.ToInt32(RV);
        e.Command.Parameters["@ColorId"].Value = ColorSelected;
    }
}
best Regards,

Erik
Reply With Quote
  #7 (permalink)  
Old June 6th, 2013, 11:21 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Maybe they fire in a different order than you expect? Also, since it's a page based value, RV goes out of scope after each page load (and postback).

I would abstract the logic to calculate RV to a separate method and call that from the Selecting event.

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!
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
Filtering XML data aldwinenriquez XSLT 7 August 25th, 2008 03:24 AM
data filtering from combobox MAKO C# 4 June 1st, 2006 03:54 AM
Filtering User data donydog Classic ASP Databases 0 February 6th, 2006 09:33 PM
Need Help on Filtering duplicated data fanyin XSLT 2 November 4th, 2004 08:06 PM
Filtering data by code rodrigoss BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 June 23rd, 2004 02:06 PM



All times are GMT -4. The time now is 05:19 AM.


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