Wednesday, 7 August 2013

ASP.NET GridView & SqlDataSource FilterExpression - Column name with hash / pound symbol

ASP.NET GridView & SqlDataSource FilterExpression - Column name with hash
/ pound symbol

I am working with a brilliantly designed table, where the primary key
column is OTTXN#
I need to be able to select and display these values in the GridView which
is populated from my SqlDataSource, which is working fine.
When i add FilterExpression=" = '{0}'" then the code craps out on me,
because the column name has a hash tag / pound symbol in it.
I'm able to alter the select statement to use an alias without the pound
symbol, but SQL where clauses dont allow you to use a column alias.
Any way i can get this to work?
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="dsIseries">
<Columns>
<asp:BoundField DataField="OTTXN#" HeaderText="OTTXN"
SortExpression="OTTXN" />
<asp:BoundField DataField="OTWODT" HeaderText="OTWODT"
SortExpression="OTWODT" />
<asp:BoundField DataField="OTBAD1" HeaderText="OTBAD1"
SortExpression="OTBAD1" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsIseries" runat="server"
ConnectionString="<%$ ConnectionStrings:VM520ConnectionString %>"
ProviderName="<%$
ConnectionStrings:VM520ConnectionString.ProviderName %>"
SelectCommand='SELECT ottxn#, otwodt, otbad1
FROM kivalib.ortxnpf
fetch first 100 rows only'
FilterExpression=" = '{0}'">
<FilterParameters>
<asp:ControlParameter ControlID="txtSearch"
PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>

No comments:

Post a Comment