By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,356 Members | 1,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,356 IT Pros & Developers. It's quick & easy.

Changing FilterExpression

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.