2011-08-08 13 views
-1

制御パラメータを使用してグリッド表示を検索していますが、コードではテキストのみを検索し、整数値は検索しません。 だから私は私のコードがある制御パラメータを使用して整数値を検索したいコードを記入してください..asp.netの制御パラメータ

:事前に

<%@ 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"> 
    `enter code here`.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" />&nbsp;&nbsp; 
       <asp:ImageButton ID="btnSearch" ImageUrl="images/searchbutton.png" runat="server" 
        Style="top: 5px; position: relative" />&nbsp;&nbsp; 
       <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> 

おかげで、

ネアシュ

+0

あなたの問題を解決するためのコードと詳細を提供してください。 –

+0

@just_name:私はコードを編集中です。そして私に解決策を教えてください。 – Naresh

答えて

0

あなたは別のOR条件をフィルタに追加して、整数列と一致させ、適切なフィルタを追加することができますメートル...それはあなたが意味するものですか?

<asp:SqlDataSource 
    ID="dsGridview" 
    runat="server" 
    ConnectionString="<%$ ConnectionStrings:EvonetConnectionString %>" 
    SelectCommand="SELECT * FROM [T_Employees]" 
    FilterExpression="firstname like '%{0}%' or lastname like '%{1}%' or IntColumn = '{2}'"> 
    <FilterParameters> 
     <asp:ControlParameter Name="firstname" ControlID="txtSearch" PropertyName="Text" /> 
     <asp:ControlParameter Name="lastname" ControlID="txtSearch" PropertyName="Text" /> 
     <asp:ControlParameter Name="IntColumn" ControlID="txtSearch" PropertyName="Text" /> 
    </FilterParameters> 
</asp:SqlDataSource> 

注意すべき重要なことは、あなたがinteger列にlikeを使用することができないということです...よくそれをキャストすることなく、最初の私は推測していません。

+0

整数でEmp_Idを作成していますが、エラー:Microsoft JScriptランタイムエラーが表示されていました:Sys.WebForms.PageRequestServerErrorException:System.Int32.and System.Stringで 'like'操作を実行できません。 Plese help me; – Naresh