I am searching a grid view using control parameters, but in my code I search only for text instead of integer values.
How can I search for integer values using control parameters?
My code is:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridviewwithHighlightedSearch.aspx.vb"
Inherits="GridviewwithHighlightedSearch" MasterPageFile="~/Default.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderMain" runat="Server">
<style type="text/css">
.highlight {text-decoration: none;color:black;background:yellow;}
</style>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<h3>
Gridview with Highlighted Search</h3>
<div class="GridviewDiv">
<p>
Search for a person :
<asp:TextBox ID="txtSearch" runat="server" />
<asp:ImageButton ID="btnSearch" ImageUrl="images/searchbutton.png" runat="server"
Style="top: 5px; position: relative" />
<asp:ImageButton ID="btnClear" ImageUrl="images/clearbutton.png" runat="server" Style="top: 5px;
position: relative" /><br />
<br />
</p>
<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" AllowPaging="True"
AllowSorting="true" DataSourceID="dsGridview" Width="540px" PageSize="10" CssClass="Gridview">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" ItemStyle-Width="40px"
ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="First Name" SortExpression="FirstName">
<ItemStyle Width="120px" HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblFirstname" Text='<%# HighlightText(Eval("FirstName")) %>' runat="server"
CssClass="TextField" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name" SortExpression="LastName">
<ItemStyle Width="120px" HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lblLastname" Text='<%# HighlightText(Eval("LastName")) %>' runat="server"
CssClass="TextField" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department"
ItemStyle-Width="130px" />
<asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location"
ItemStyle-Width="130px" />
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<a href="GridviewwithHighlightedSearch.zip">Download Source Code</a>
<asp:SqlDataSource ID="dsGridview" runat="server" ConnectionString="<%$ ConnectionStrings:EvonetConnectionString %>"
SelectCommand="SELECT * FROM [T_Employees]" FilterExpression="firstname like '%{0}%' or lastname like '%{1}%'">
<FilterParameters>
<asp:ControlParameter Name="firstname" ControlID="txtSearch" PropertyName="Text" />
<asp:ControlParameter Name="lastname" ControlID="txtSearch" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
</form>
</asp:Content>
You could just add another
ORcondition to your filter to match the integer column and add the appropriate filter parameter…is that what you mean?The important thing to note is that you cannot use
likeon anintegercolumn…well not without casting it first I guess.