473,626 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing FilterExpressio n

I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpressio n on a
SqlDataSource. Can someone tell me what I am doing wrong? Below is the
SelectCommand:

<asp:SqlDataSou rce ID="SqlClosedRe ason" runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:WcccuConnect ionString %>"

SelectCommand=" SELECT NULL As seq_nbr, '-none-' As reason, 1 As active UNION
SELECT [seq_nbr], [reason], [active] FROM [activity_closed _reasons]"

FilterExpressio n = "active={0} ">

<FilterParamete rs>

<asp:ControlPar ameter ControlID="txtA ctive" PropertyName="T ext"
Name="pactive" DefaultValue="1 " Type="Byte" />

</FilterParameter s>

</asp:SqlDataSour ce>

In my VB code at the top of the page I am doing the following:

SqlClosedReason .FilterExpressi on = ""

When the page tries to open for a specific record, it gives me the following
error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control.

If I comment out the setting of the FilterExpressio n the error goes away.

p.s. This is populating a DropDownList.

David
Oct 4 '06 #1
4 11743
Remove the sqldatasource and re-add it to the form. Run it without the
filter, then add the filter if you need to. This is a *vanilla install
technique.

--
_______________ _________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"David" <dl*****@lifeti meinc.comwrote in message
news:O7******** ******@TK2MSFTN GP04.phx.gbl...
>I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpressio n on a
SqlDataSourc e. Can someone tell me what I am doing wrong? Below is the
SelectComman d:

<asp:SqlDataSou rce ID="SqlClosedRe ason" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:WcccuConnect ionString %>"

SelectCommand=" SELECT NULL As seq_nbr, '-none-' As reason, 1 As active
UNION SELECT [seq_nbr], [reason], [active] FROM [activity_closed _reasons]"

FilterExpressio n = "active={0} ">

<FilterParamete rs>

<asp:ControlPar ameter ControlID="txtA ctive" PropertyName="T ext"
Name="pactive" DefaultValue="1 " Type="Byte" />

</FilterParameter s>

</asp:SqlDataSour ce>

In my VB code at the top of the page I am doing the following:

SqlClosedReason .FilterExpressi on = ""

When the page tries to open for a specific record, it gives me the
following error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used
in the context of a databound control.

If I comment out the setting of the FilterExpressio n the error goes away.

p.s. This is populating a DropDownList.

David


Oct 4 '06 #2
Nope. Still a problem.

David

"Alvin Bruney [MVP]" <www.lulu.com/owcwrote in message
news:e7******** ******@TK2MSFTN GP05.phx.gbl...
Remove the sqldatasource and re-add it to the form. Run it without the
filter, then add the filter if you need to. This is a *vanilla install
technique.

--
_______________ _________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"David" <dl*****@lifeti meinc.comwrote in message
news:O7******** ******@TK2MSFTN GP04.phx.gbl...
>>I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpressio n on
a SqlDataSource. Can someone tell me what I am doing wrong? Below is the
SelectCommand :

<asp:SqlDataSo urce ID="SqlClosedRe ason" runat="server"
ConnectionStri ng="<%$ ConnectionStrin gs:WcccuConnect ionString %>"

SelectCommand= "SELECT NULL As seq_nbr, '-none-' As reason, 1 As active
UNION SELECT [seq_nbr], [reason], [active] FROM
[activity_closed _reasons]"

FilterExpressi on = "active={0} ">

<FilterParamet ers>

<asp:ControlPa rameter ControlID="txtA ctive" PropertyName="T ext"
Name="pactiv e" DefaultValue="1 " Type="Byte" />

</FilterParameter s>

</asp:SqlDataSour ce>

In my VB code at the top of the page I am doing the following:

SqlClosedReaso n.FilterExpress ion = ""

When the page tries to open for a specific record, it gives me the
following error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used
in the context of a databound control.

If I comment out the setting of the FilterExpressio n the error goes away.

p.s. This is populating a DropDownList.

David



Oct 5 '06 #3
I forgot to mention that the sqldatasource is in a dropdownlist in a
FormView - if that matters.

David

"Alvin Bruney [MVP]" <www.lulu.com/owcwrote in message
news:e7******** ******@TK2MSFTN GP05.phx.gbl...
Remove the sqldatasource and re-add it to the form. Run it without the
filter, then add the filter if you need to. This is a *vanilla install
technique.

--
_______________ _________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"David" <dl*****@lifeti meinc.comwrote in message
news:O7******** ******@TK2MSFTN GP04.phx.gbl...
>>I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpressio n on
a SqlDataSource. Can someone tell me what I am doing wrong? Below is the
SelectCommand :

<asp:SqlDataSo urce ID="SqlClosedRe ason" runat="server"
ConnectionStri ng="<%$ ConnectionStrin gs:WcccuConnect ionString %>"

SelectCommand= "SELECT NULL As seq_nbr, '-none-' As reason, 1 As active
UNION SELECT [seq_nbr], [reason], [active] FROM
[activity_closed _reasons]"

FilterExpressi on = "active={0} ">

<FilterParamet ers>

<asp:ControlPa rameter ControlID="txtA ctive" PropertyName="T ext"
Name="pactiv e" DefaultValue="1 " Type="Byte" />

</FilterParameter s>

</asp:SqlDataSour ce>

In my VB code at the top of the page I am doing the following:

SqlClosedReaso n.FilterExpress ion = ""

When the page tries to open for a specific record, it gives me the
following error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used
in the context of a databound control.

If I comment out the setting of the FilterExpressio n the error goes away.

p.s. This is populating a DropDownList.

David



Oct 5 '06 #4
Sorry for misreading your post. The reason you are having this error is
because a filter expression is implicitly bound to a parameter list and the
empty filter is breaking that guarantee.

There are a couple approaches you can take depending on what you want to do.
I suspect you want the grid to come up initiallly unfiltered and then use
the drop down to filter the grid? If this assumption is correct, you can do
this thru the declarative source control by adding an empty list item to the
dropdown as the selected, first item. However, you won't be able to put a
"Select Active Items" as the first option in the list box.

You can ignore the declarative syntax and use the codebehind to get around
this limitation. Air code:
if (!IsPostBack)
{
SqlDataSource1. FilterExpressio n = string.Empty;
System.Web.UI.W ebControls.Para meter pc = new Parameter();
SqlDataSource1. FilterParameter s.Add(pc);
}
else
{

//clear is required
SqlDataSource1. FilterParameter s.Clear();
ControlParamete r cprViewState = new ControlParamete r();
cprViewState.Co ntrolID = DropDownList1.I D.ToString();
cprViewState.Pr opertyName = "SelectedValue" ;
cprViewState.Na me = "ViewState" ;
cprViewState.Ty pe = TypeCode.String ;
SqlDataSource1. FilterExpressio n = "Title='{0} '";
SqlDataSource1. FilterParameter s.Add(cprViewSt ate);

GridView1.DataB ind();

}
--
_______________ _________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"David" <dl*****@lifeti meinc.comwrote in message
news:e1******** ******@TK2MSFTN GP04.phx.gbl...
>I forgot to mention that the sqldatasource is in a dropdownlist in a
FormView - if that matters.

David

"Alvin Bruney [MVP]" <www.lulu.com/owcwrote in message
news:e7******** ******@TK2MSFTN GP05.phx.gbl...
>Remove the sqldatasource and re-add it to the form. Run it without the
filter, then add the filter if you need to. This is a *vanilla install
technique.

--
______________ __________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"David" <dl*****@lifeti meinc.comwrote in message
news:O7******* *******@TK2MSFT NGP04.phx.gbl.. .
>>>I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpressio n on
a SqlDataSource. Can someone tell me what I am doing wrong? Below is
the SelectCommand:

<asp:SqlDataS ource ID="SqlClosedRe ason" runat="server"
ConnectionStr ing="<%$ ConnectionStrin gs:WcccuConnect ionString %>"

SelectCommand ="SELECT NULL As seq_nbr, '-none-' As reason, 1 As active
UNION SELECT [seq_nbr], [reason], [active] FROM
[activity_closed _reasons]"

FilterExpress ion = "active={0} ">

<FilterParame ters>

<asp:ControlP arameter ControlID="txtA ctive" PropertyName="T ext"
Name="pactive " DefaultValue="1 " Type="Byte" />

</FilterParameter s>

</asp:SqlDataSour ce>

In my VB code at the top of the page I am doing the following:

SqlClosedReas on.FilterExpres sion = ""

When the page tries to open for a specific record, it gives me the
following error:

Databinding methods such as Eval(), XPath(), and Bind() can only be used
in the context of a databound control.

If I comment out the setting of the FilterExpressio n the error goes
away.

p.s. This is populating a DropDownList.

David




Oct 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
18874
by: fuchs.markus | last post by:
Hello, on my page, I have a DetailsViewControl connected to a SqlDataSource. Now when I dynamically set the FilterExpression and FilterParameters - for example in a OnClick-EventHandler of a button - the DetailsView shows the filtered Data, but Deleting and Updating doesn't work anymore. The DetailsView changes to EditMode, but after clicking on the UpdateButton it shows the old data. Am I missing something or is it just not possible or...
1
6506
by: Henry Habermacher [MVP Access] | last post by:
Environment: VS2005, ASP.Net 2.0, SQLServer 2000, VB.Net, IIS6 I use a GridView Control which is based on a SQLDataSource. The datasource is based on a Select statement and is filtered by the FilterExpression. The GridView also has a pager element (below, displaying first, previous, next, last icons), paging is enabled, page contains 10 rows. The user now skips some pages by clicking a view times on the next icon. Now he changes the...
2
7777
by: DummyDumb | last post by:
Hi, I've got a Gridview utilizing a filterexpression: <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OnDeleted="ItemDeleted" EnableCaching="true" SqlCacheDependency="APP_TIMESHEET:AB" CacheKeyDependency="AB" SelectMethod="GetABs" TypeName="RetrieveABData" DeleteMethod="DeleteAB"
4
10234
by: John | last post by:
How can I find how many rows are returned from the DataView generated by FilterExpression on an ObjectDataSource? I can get the number of rows in the underlying datatable by using: protected void mydataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e) { numrows = ((DataTable) e.ReturnValue).Rows.Count; }
0
1337
by: wubin_98 | last post by:
When I set a SqlDataSource1.FilterExpression value to " Partnumber LIKE '87-2055-___'" , SqlDataSource return empty. But I can get correct result in SQL query by including above expression. I also found that FilterExpression only support % (Any string of zero or more characters) in the end of string. For example, "Partnumber LIKE '87-2055-%' (OK). But "Partnumber LIKE '87-20%-012'" (Error). Could anyone give an explanation?
1
1799
by: j.gibson | last post by:
VS 2005 C# ASP.NET I have a Gridview which is filled from an objectdatasource. I have some filtering - which works perfectly when the field to be filtered is an INT. dscIssues.FilterExpression += " and (assignedtoid = 1)" works ok
1
3043
by: mosscliffe | last post by:
I am trying to filter an accessdatsource by adding a FilterExpression If I have Field = 2 It works fine If I have Field IN (1,5,7) it works fine So now I want it to reference a dropdownlist so I try Field = ddlCats.SelectedValue - Fails Miserably So I read further and try
1
7054
by: jobs | last post by:
Cannot find column . Am I missing something here... SelectCommand="SELECT , , , refid FROM " FilterExpression="phone_nbr like @phone_nbr + '%'"
3
5161
by: Curt | last post by:
I have a gridview object with a sqldatasource as its sourceid. Everything was going so well until I came across this problem. My SELECTCOMMAND for my sqldatasource is: select alertid,subject,createdt,eventid,eventname, statuscd,trgid from vwAlerts order by createdt desc Now, based on a fiew input fields, I put together a WHERE clause for the filterexpression. For example, this filterexpression works great:
0
8644
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8514
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7206
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6126
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2632
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1516
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.