p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=560)
-   -   Filtering data (http://p2p.wrox.com/showthread.php?t=90283)

Erik Severiens June 6th, 2013 06:07 AM

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

Imar June 6th, 2013 06:10 AM

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 June 6th, 2013 06:12 AM

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

Erik Severiens June 6th, 2013 06:26 AM

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

Imar June 6th, 2013 07:36 AM

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

Erik Severiens June 6th, 2013 11:15 AM

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

Imar June 6th, 2013 11:21 AM

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


All times are GMT -4. The time now is 01:24 AM.

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