Changing FilterExpression

D

David

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
 
A

Alvin Bruney [MVP]

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
 
D

David

Nope. Still a problem.

David

Alvin Bruney said:
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 said:
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
 
D

David

I forgot to mention that the sqldatasource is in a dropdownlist in a
FormView - if that matters.

David

Alvin Bruney said:
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 said:
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
 
A

Alvin Bruney [MVP]

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 said:
I forgot to mention that the sqldatasource is in a dropdownlist in a
FormView - if that matters.

David

Alvin Bruney said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top