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

Programmatically set FilterExpression and FilterParameters of SqlDataSource

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

<asp:DetailsView 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>
</asp:DetailsView>

<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>
<asp:Parameter Name="original_CustomerID" Type="String"
/>
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CompanyName" Type="String" />
<asp:Parameter Name="ContactName" Type="String" />
<asp:Parameter Name="ContactTitle" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="Region" Type="String" />
<asp:Parameter Name="PostalCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
<asp:Parameter Name="original_CustomerID" Type="String"
/>
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="CompanyName" Type="String" />
<asp:Parameter Name="ContactName" Type="String" />
<asp:Parameter Name="ContactTitle" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="Region" Type="String" />
<asp:Parameter Name="PostalCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="Fax" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

Thanks in advance
Markus Fuchs

Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


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

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.