Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 为什么不是';是否使用返回整数值的控制参数进行搜索?_Asp.net_Vb.net - Fatal编程技术网

Asp.net 为什么不是';是否使用返回整数值的控制参数进行搜索?

Asp.net 为什么不是';是否使用返回整数值的控制参数进行搜索?,asp.net,vb.net,Asp.net,Vb.net,我正在使用控制参数搜索网格视图,但在我的代码中,我只搜索文本而不是整数值 如何使用控制参数搜索整数值 我的代码是: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridviewwithHighlightedSearch.aspx.vb" Inherits="GridviewwithHighlightedSearch" MasterPageFile="~/Default.master" %> <as

我正在使用控制参数搜索网格视图,但在我的代码中,我只搜索文本而不是整数值

如何使用控制参数搜索整数值

我的代码是:

   <%@ 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" />&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>
</asp:Content>

您只需将另一个
条件添加到过滤器中,以匹配整数列并添加适当的过滤器参数……这就是您的意思吗

<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>


需要注意的重要一点是,您不能在
整数
列上使用
like
,我想,如果不先强制转换它,就不能使用它。

我正在使用整数创建Emp_Id,但它显示了一个错误:Microsoft JScript运行时错误:Sys.WebForms.PageRequestServerErrorException:无法在System.Int32.and上执行“like”操作System.String。请帮助我;