Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Programmatically set FilterExpression and FilterParameters of SqlDataSource

Reply
Thread Tools

Programmatically set FilterExpression and FilterParameters of SqlDataSource

 
 
fuchs.markus@gmail.com
Guest
Posts: n/a
 
      08-25-2005
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 perhaps a beta
problem?

Here is my Button-Click-EventHandler:

protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.FilterExpression = "CompanyName LIKE '{0}'";
SqlDataSource1.FilterParameters.Add("CompanyName", "A*");
}


And here my Page-SourceCode:

<aspetailsView ID="DetailsView1" runat="server"
AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="CustomerID" DataSourceID="SqlDataSource3"
Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="CustomerID"
HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName"
HeaderText="CompanyName" SortExpression="CompanyName" />
<asp:BoundField DataField="ContactName"
HeaderText="ContactName" SortExpression="ContactName" />
<asp:BoundField DataField="ContactTitle"
HeaderText="ContactTitle" SortExpression="ContactTitle" />
<asp:BoundField DataField="Address"
HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City"
SortExpression="City" />
<asp:BoundField DataField="Region" HeaderText="Region"
SortExpression="Region" />
<asp:BoundField DataField="PostalCode"
HeaderText="PostalCode" SortExpression="PostalCode" />
<asp:BoundField DataField="Country"
HeaderText="Country" SortExpression="Country" />
<asp:BoundField DataField="Phone" HeaderText="Phone"
SortExpression="Phone" />
<asp:BoundField DataField="Fax" HeaderText="Fax"
SortExpression="Fax" />
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</aspetailsView>

<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString5 %>"
DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] =
@original_CustomerID"
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_CustomerID" OnUpdated="SqlDataSource3_Updated"
OnUpdating="SqlDataSource3_Updating">
<DeleteParameters>
<asparameter Name="original_CustomerID" Type="String"
/>
</DeleteParameters>
<UpdateParameters>
<asparameter Name="CompanyName" Type="String" />
<asparameter Name="ContactName" Type="String" />
<asparameter Name="ContactTitle" Type="String" />
<asparameter Name="Address" Type="String" />
<asparameter Name="City" Type="String" />
<asparameter Name="Region" Type="String" />
<asparameter Name="PostalCode" Type="String" />
<asparameter Name="Country" Type="String" />
<asparameter Name="Phone" Type="String" />
<asparameter Name="Fax" Type="String" />
<asparameter Name="original_CustomerID" Type="String"
/>
</UpdateParameters>
<InsertParameters>
<asparameter Name="CustomerID" Type="String" />
<asparameter Name="CompanyName" Type="String" />
<asparameter Name="ContactName" Type="String" />
<asparameter Name="ContactTitle" Type="String" />
<asparameter Name="Address" Type="String" />
<asparameter Name="City" Type="String" />
<asparameter Name="Region" Type="String" />
<asparameter Name="PostalCode" Type="String" />
<asparameter Name="Country" Type="String" />
<asparameter Name="Phone" Type="String" />
<asparameter Name="Fax" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

Thanks in advance
Markus Fuchs

 
Reply With Quote
 
 
 
 
Markus
Guest
Posts: n/a
 
      08-25-2005
Hi all,
I've found a solution to my problem: If I leave the FilterParameters
alone and write keys as well as values in the FilterExpression-String,
everything works properly.

MF

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView - Changing FilterExpression of SQLDataSource and Paging Henry Habermacher [MVP Access] ASP .Net 2 07-31-2007 04:05 AM
sqldatasource filterexpression and paging lewis ASP .Net 0 01-10-2007 04:52 PM
sqldatasource filterexpression and paging lewis ASP .Net 0 01-09-2007 09:42 PM
SqlDataSource FilterExpression doesn't support LIKE + 'String__' pattern wubin_98@yahoo.com ASP .Net 0 04-07-2006 06:31 PM
Dynamically Add FilterExpression and FilterParameters Mariela Donkova ASP .Net Web Controls 0 01-10-2006 01:27 PM



Advertisments