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

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
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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:12 AM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
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
|

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
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |
All times are GMT -4. The time now is 02:38 AM.
|