 |
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 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
|
|
|
|
|

June 6th, 2013, 06:07 AM
|
|
Authorized User
|
|
Join Date: May 2013
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 6th, 2013, 06:10 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

June 6th, 2013, 06:26 AM
|
|
Authorized User
|
|
Join Date: May 2013
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 6th, 2013, 07:36 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

June 6th, 2013, 11:15 AM
|
|
Authorized User
|
|
Join Date: May 2013
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 6th, 2013, 11:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
 |
|