473,511 Members | 14,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing FilterExpression

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

<asp:SqlDataSource ID="SqlClosedReason" runat="server" ConnectionString="<%$
ConnectionStrings:WcccuConnectionString %>"

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

FilterExpression = "active={0}">

<FilterParameters>

<asp:ControlParameter ControlID="txtActive" PropertyName="Text"
Name="pactive" DefaultValue="1" Type="Byte" />

</FilterParameters>

</asp:SqlDataSource>

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

SqlClosedReason.FilterExpression = ""

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 FilterExpression the error goes away.

p.s. This is populating a DropDownList.

David
Oct 4 '06 #1
4 11738
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*****@lifetimeinc.comwrote in message
news:O7**************@TK2MSFTNGP04.phx.gbl...
>I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpression on a
SqlDataSource. Can someone tell me what I am doing wrong? Below is the
SelectCommand:

<asp:SqlDataSource ID="SqlClosedReason" runat="server"
ConnectionString="<%$ ConnectionStrings:WcccuConnectionString %>"

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

FilterExpression = "active={0}">

<FilterParameters>

<asp:ControlParameter ControlID="txtActive" PropertyName="Text"
Name="pactive" DefaultValue="1" Type="Byte" />

</FilterParameters>

</asp:SqlDataSource>

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

SqlClosedReason.FilterExpression = ""

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 FilterExpression 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**************@TK2MSFTNGP05.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*****@lifetimeinc.comwrote in message
news:O7**************@TK2MSFTNGP04.phx.gbl...
>>I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpression on
a SqlDataSource. Can someone tell me what I am doing wrong? Below is the
SelectCommand:

<asp:SqlDataSource ID="SqlClosedReason" runat="server"
ConnectionString="<%$ ConnectionStrings:WcccuConnectionString %>"

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

FilterExpression = "active={0}">

<FilterParameters>

<asp:ControlParameter ControlID="txtActive" PropertyName="Text"
Name="pactive" DefaultValue="1" Type="Byte" />

</FilterParameters>

</asp:SqlDataSource>

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

SqlClosedReason.FilterExpression = ""

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 FilterExpression 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**************@TK2MSFTNGP05.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*****@lifetimeinc.comwrote in message
news:O7**************@TK2MSFTNGP04.phx.gbl...
>>I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpression on
a SqlDataSource. Can someone tell me what I am doing wrong? Below is the
SelectCommand:

<asp:SqlDataSource ID="SqlClosedReason" runat="server"
ConnectionString="<%$ ConnectionStrings:WcccuConnectionString %>"

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

FilterExpression = "active={0}">

<FilterParameters>

<asp:ControlParameter ControlID="txtActive" PropertyName="Text"
Name="pactive" DefaultValue="1" Type="Byte" />

</FilterParameters>

</asp:SqlDataSource>

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

SqlClosedReason.FilterExpression = ""

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 FilterExpression 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.FilterExpression = string.Empty;
System.Web.UI.WebControls.Parameter pc = new Parameter();
SqlDataSource1.FilterParameters.Add(pc);
}
else
{

//clear is required
SqlDataSource1.FilterParameters.Clear();
ControlParameter cprViewState = new ControlParameter();
cprViewState.ControlID = DropDownList1.ID.ToString();
cprViewState.PropertyName = "SelectedValue";
cprViewState.Name = "ViewState";
cprViewState.Type = TypeCode.String;
SqlDataSource1.FilterExpression = "Title='{0}'";
SqlDataSource1.FilterParameters.Add(cprViewState);

GridView1.DataBind();

}
--
________________________
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*****@lifetimeinc.comwrote in message
news:e1**************@TK2MSFTNGP04.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**************@TK2MSFTNGP05.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*****@lifetimeinc.comwrote in message
news:O7**************@TK2MSFTNGP04.phx.gbl...
>>>I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpression on
a SqlDataSource. Can someone tell me what I am doing wrong? Below is
the SelectCommand:

<asp:SqlDataSource ID="SqlClosedReason" runat="server"
ConnectionString="<%$ ConnectionStrings:WcccuConnectionString %>"

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

FilterExpression = "active={0}">

<FilterParameters>

<asp:ControlParameter ControlID="txtActive" PropertyName="Text"
Name="pactive" DefaultValue="1" Type="Byte" />

</FilterParameters>

</asp:SqlDataSource>

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

SqlClosedReason.FilterExpression = ""

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 FilterExpression 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
18860
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...
1
6493
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...
2
7769
by: DummyDumb | last post by:
Hi, I've got a Gridview utilizing a filterexpression: <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OnDeleted="ItemDeleted" EnableCaching="true"...
4
10229
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...
0
1315
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...
1
1794
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. ...
1
3036
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...
1
7047
by: jobs | last post by:
Cannot find column . Am I missing something here... SelectCommand="SELECT , , , refid FROM " FilterExpression="phone_nbr like @phone_nbr + '%'"
3
5153
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...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
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...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
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...
0
4743
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...
0
3230
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
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...

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.