473,609 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y set FilterExpressio n and FilterParameter s of SqlDataSource

Hello,
on my page, I have a DetailsViewCont rol connected to a SqlDataSource.
Now when I dynamically set the FilterExpressio n and FilterParameter s -
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 perhaps a beta
problem?

Here is my Button-Click-EventHandler:

protected void Button1_Click(o bject sender, EventArgs e)
{
SqlDataSource1. FilterExpressio n = "CompanyNam e LIKE '{0}'";
SqlDataSource1. FilterParameter s.Add("CompanyN ame", "A*");
}
And here my Page-SourceCode:

<asp:DetailsVie w ID="DetailsView 1" runat="server"
AllowPaging="Tr ue" AutoGenerateRow s="False"
DataKeyNames="C ustomerID" DataSourceID="S qlDataSource3"
Height="50px" Width="125px">
<Fields>
<asp:BoundFie ld DataField="Cust omerID"
HeaderText="Cus tomerID" ReadOnly="True" SortExpression= "CustomerID " />
<asp:BoundFie ld DataField="Comp anyName"
HeaderText="Com panyName" SortExpression= "CompanyNam e" />
<asp:BoundFie ld DataField="Cont actName"
HeaderText="Con tactName" SortExpression= "ContactNam e" />
<asp:BoundFie ld DataField="Cont actTitle"
HeaderText="Con tactTitle" SortExpression= "ContactTit le" />
<asp:BoundFie ld DataField="Addr ess"
HeaderText="Add ress" SortExpression= "Address" />
<asp:BoundFie ld DataField="City " HeaderText="Cit y"
SortExpression= "City" />
<asp:BoundFie ld DataField="Regi on" HeaderText="Reg ion"
SortExpression= "Region" />
<asp:BoundFie ld DataField="Post alCode"
HeaderText="Pos talCode" SortExpression= "PostalCode " />
<asp:BoundFie ld DataField="Coun try"
HeaderText="Cou ntry" SortExpression= "Country" />
<asp:BoundFie ld DataField="Phon e" HeaderText="Pho ne"
SortExpression= "Phone" />
<asp:BoundFie ld DataField="Fax" HeaderText="Fax "
SortExpression= "Fax" />
<asp:CommandFie ld ShowDeleteButto n="True"
ShowEditButton= "True" ShowInsertButto n="True" />
</Fields>
</asp:DetailsView >

<asp:SqlDataSou rce ID="SqlDataSour ce3" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:NorthwindCon nectionString5 %>"
DeleteCommand=" DELETE FROM [Customers] WHERE [CustomerID] =
@original_Custo merID"
InsertCommand=" INSERT INTO [Customers] ([CustomerID],
[CompanyName], [ContactName], [ContactTitle], [Address], [City],
[Region], [PostalCode], [Country], [Phone], [Fax]) VALUES (@CustomerID,
@CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region,
@PostalCode, @Country, @Phone, @Fax)"
SelectCommand=" SELECT * FROM [Customers]"
UpdateCommand=" UPDATE [Customers] SET [CompanyName] = @CompanyName,
[ContactName] = @ContactName, [ContactTitle] = @ContactTitle, [Address]
= @Address, [City] = @City, [Region] = @Region, [PostalCode] =
@PostalCode, [Country] = @Country, [Phone] = @Phone, [Fax] = @Fax WHERE
[CustomerID] = @original_Custo merID" OnUpdated="SqlD ataSource3_Upda ted"
OnUpdating="Sql DataSource3_Upd ating">
<DeleteParamete rs>
<asp:Paramete r Name="original_ CustomerID" Type="String"
/>
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="CompanyNa me" Type="String" />
<asp:Paramete r Name="ContactNa me" Type="String" />
<asp:Paramete r Name="ContactTi tle" Type="String" />
<asp:Paramete r Name="Address" Type="String" />
<asp:Paramete r Name="City" Type="String" />
<asp:Paramete r Name="Region" Type="String" />
<asp:Paramete r Name="PostalCod e" Type="String" />
<asp:Paramete r Name="Country" Type="String" />
<asp:Paramete r Name="Phone" Type="String" />
<asp:Paramete r Name="Fax" Type="String" />
<asp:Paramete r Name="original_ CustomerID" Type="String"
/>
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="CustomerI D" Type="String" />
<asp:Paramete r Name="CompanyNa me" Type="String" />
<asp:Paramete r Name="ContactNa me" Type="String" />
<asp:Paramete r Name="ContactTi tle" Type="String" />
<asp:Paramete r Name="Address" Type="String" />
<asp:Paramete r Name="City" Type="String" />
<asp:Paramete r Name="Region" Type="String" />
<asp:Paramete r Name="PostalCod e" Type="String" />
<asp:Paramete r Name="Country" Type="String" />
<asp:Paramete r Name="Phone" Type="String" />
<asp:Paramete r Name="Fax" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>

Thanks in advance
Markus Fuchs

Nov 19 '05 #1
1 18872
Hi all,
I've found a solution to my problem: If I leave the FilterParameter s
alone and write keys as well as values in the FilterExpressio n-String,
everything works properly.

MF

Nov 19 '05 #2

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

Similar topics

0
1402
by: Andre | last post by:
Hi, I use a FilterExpression (FilterParameters) to select the value to be displayed in my DetailsView, but when i select a row in my GridView, the DetailsView retun this error: Cannot perform '=' operation on System.Int32 and System.String. The noauto in my DB is an Int32, but in my paramters i put type="int32", but it does'nt work.
1
6505
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...
3
4522
by: simonZ | last post by:
In gridView I have dropdown list : <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
1
1926
by: Bruno Alexandre | last post by:
Hi guys... I have this <asp:SqlDataSource ID="dsProdutos2" runat="server" SelectCommand="SELECT * FROM " FilterExpression="idProduct='@idProduct'"
4
11743
by: David | last post by:
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 , , FROM "
0
1490
by: blouie | last post by:
I'm combining a "SELECT Scope_Identity..." statement with an insert statement in my InsertCommand. When I try to retrieve the value into a variable, it generates an error stating that my collumn "myScope_Identity" is invalid. If I run the SQL statements in Query Analyzer, it works just fine. In Enterprise Manager, it does not generate an error but it doesn't return any data back. Any help would be greatly appreciated.
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 + '%'"
0
1045
by: Radu | last post by:
Hi. On the first page of my website the user selects one document which can be in either English or French. I store that choice in a class, and I can extract it with: CType(Session("UsersSessionClass"), UserSessionClass).SelLanguage Later in my 'wizard' I have a page which contains this html: __________________________________________________________________ <form id="frmStep4ConfigureDoYous" runat="server"> <%-- Store the language...
1
3867
by: sm2010 | last post by:
Hi, I have a SQLDatasource control on a web page. It is the datasource for a gridview control. At the moment i have in the contractID and duration text property the symbol '%', however If I make the TextBox empty or remove the % from the contractID and duration Textbox it returns all the names in the database when i first run the script. How do I get the gridview to be blank when i first run the script without having to use the % in...
0
8139
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8091
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8555
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...
1
8232
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7024
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
6064
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
4032
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...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.