I have a ASP.Net web page with a grid view. I want to filter the grid view data based on the selection of a drop down list. I have this working fine on another page. The difference on the problem page is that the column I need to filter against is an int rather than a varchar. When I load the page I get the error message: Input string was not in a correct format.
I have pasted code for the dropdownlist and datasource below. This must be a common requirement so I guess I'm missing something obvious...? On attempting to find a resolution via Google, other have the same problem. A post on very similar lines can be found at http://www.velocityreviews.com/forums/t123088-problem-in-filterparameters.html, unfortunately Gavin's resolution didn't work for me.
Many thanks,
Rob.
<%@ Page Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeFile="BacheAccountSettings.aspx.cs"
Inherits="RDM.BacheTradeLoad" Title="Untitled Page" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<tr>
<td style="width: 100px;">
Filter:
</td>
<td style="width: 170px;">
<asp:DropDownList ID="ddlAccountSourceId" DataSourceID="dsAccountSourceId" AutoPostBack="true"
DataValueField="AccountId" runat="server" Width="130px" Font-Size="11px" AppendDataBoundItems="true">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="1">
<asp:GridView ID="grdRefBacheAccount" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#E7E开发者_运维百科7FF" BorderWidth="1px" CellPadding="3" DataSourceID="dsArcReference"
GridLines="Horizontal" BorderStyle="None" EnableModelValidation="True" Style="position: static"
OnRowDataBound="grdRefBacheAccount_RowDataBound" AllowPaging="True" PageSize="25"
CssClass="Grid" AllowSorting="True">
<Columns>
<asp:CommandField ShowEditButton="True" ShowCancelButton="False" />
<asp:BoundField DataField="SourceID" HeaderText="SourceID" SortExpression="SourceID" />
<asp:BoundField DataField="GroupCompany" HeaderText="GroupCompany" SortExpression="GroupCompany" />
<asp:BoundField DataField="Portfolio" HeaderText="Portfolio" SortExpression="Portfolio" />
<asp:BoundField DataField="OnBehalfComp" HeaderText="OnBehalfComp" SortExpression="OnBehalfComp" />
<asp:BoundField DataField="AssignedTrader" HeaderText="AssignedTrader" SortExpression="AssignedTrader" />
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" ForeColor="#F7F7F7" Font-Bold="True" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
</td>
</tr>
<div id="divImportButton" align="right">
<asp:Button ID="btnImport" runat="server" Text="Import Trade" OnClick="btnImport_Click"
CssClass="Button" />
</div>
<asp:SqlDataSource ID="dsArcReference" runat="server" ConnectionString="<%$ ConnectionStrings:ARC_REFERENCEConnectionString %>"
SelectCommand="select ACCOUNT_SOURCE_ID as 'AccountId',
[ACCOUNT_BTF_GROUP_COMPANY] as 'GroupCompany',
[ACCOUNT_BTF_PORTFOLIO] as 'Portfolio',
[ACCOUNT_BTF_ON_BEHALF_COMPANY] as 'OnBehalfComp',
[ACCOUNT_BTF_ASSIGNED_TRADER] as 'AssignedTrader'
from dbo.REF_BACHE_ACCOUNT" UpdateCommand="update dbo.REF_BACHE_ACCOUNT
set [ACCOUNT_BTF_GROUP_COMPANY] = @GroupCompany,
[ACCOUNT_BTF_PORTFOLIO] = @Portfolio,
[ACCOUNT_BTF_ON_BEHALF_COMPANY] = @OnBehalfComp,
[ACCOUNT_BTF_ASSIGNED_TRADER] = @AssignedTrader
where [ACCOUNT_SOURCE_ID]=@SourceID" FilterExpression="SourceID={0}">
<FilterParameters>
<asp:ControlParameter Type="Int32" ControlID="ddlAccountSourceId" PropertyName="SelectedValue" />
</FilterParameters>
<UpdateParameters>
<asp:Parameter />
<asp:Parameter Name="ACCOUNT_SOURCE_ID" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsAccountSourceId" runat="server" ConnectionString="<%$ ConnectionStrings:ARC_REFERENCEConnectionString %>"
SelectCommand="SELECT DISTINCT [ACCOUNT_SOURCE_ID] as AccountId FROM [REF_BACHE_ACCOUNT]"
DataSourceMode="DataSet"></asp:SqlDataSource>
You pass a value that is not Int32.
<asp:ListItem Text="All" Value="%"></asp:ListItem>
Remove this line and its going to work. For show them all you need to find an other way...
精彩评论