【发布时间】:2016-12-30 10:22:29
【问题描述】:
我目前有一个 gridview,其顶部有文本框,用户可以将其留空(在这种情况下,表中的所有记录都将返回),或者用户可以提供与表中相应字段中的信息完全匹配的信息将结果限制为仅那些记录的文本框具有在相应字段中具有文本框内容的那些行。我有 14 个这样的文本框,它们的任意组合都可以填充或不使用,为用户想要的记录创建过滤器。
但我想把它带到下一步。而不是要求“完全匹配”,我宁愿做一个 LIKE。本质上,如果我提供单词 dog,我希望选择有效地用作 %dog%。我已经尝试了几种不同的方法来解决这个问题,但我似乎无法得到任何工作。所以我想我会在这里发布我的代码和我所拥有的屏幕截图,看看是否有人对如何完成这项工作有任何建议。
我的 aspx 页面如下所示:
<%@ Page Title="Inventory Listing" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="InvList.aspx.cs" Inherits="CInTrac.InvList" EnableSessionState="True" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:Table runat="server" Visible="true" Width="800px">
<asp:TableHeaderRow>
<asp:TableCell Font-Size="X-Small">Asset ID</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Asset Type</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Asset Name</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Short Description</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Manufacturer</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Asset Model</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Asset Tag</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Asset Serial Number</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Deltek Asset ID</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Location Group</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Long Description</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Organization ID</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Primary IP Address</asp:TableCell>
<asp:TableCell Font-Size="X-Small">Status</asp:TableCell>
</asp:TableHeaderRow>
<asp:TableRow>
<asp:TableCell>
<asp:TextBox ID="AssetIDTbx" runat="server" Width="45px" AutoPostBack="true"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetTypeTbx" runat="server" Width="100px" AutoPostBack="True"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetNameTbx" runat="server" AutoPostBack="True"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetShortDescTbx" runat="server" AutoPostBack="True"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetManufTbx" runat="server" Width="100px" AutoPostBack="True"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetModelTbx" runat="server" Width="100px" AutoPostBack="True"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetTagTbx" runat="server" Width="100px" AutoPostBack="true"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetSerialNumTbx" runat="server" Width="100px" AutoPostBack="true"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetDTAssetIDTbx" runat="server" Width="100px" AutoPostBack="true"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetLocGrpTbx" runat="server" Width="100px" AutoPostBack="true"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetLongDescTbx" runat="server" Width="100px" AutoPostBack="true"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetOrgIDTbx" runat="server" Width="100px" AutoPostBack="true"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetPriIPAddrTbx" runat="server" Width="100px" AutoPostBack="true"></asp:TextBox></asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="AssetStatusTbx" runat="server" Width="100px" AutoPostBack="true"></asp:TextBox></asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:GridView ID="InventoryListingGV" runat="server" DataSourceID="InventoryList" OnSelectedIndexChanged="InventoryListingGV_SelectedIndexChanged" AllowPaging="True" AllowSorting="True" CellPadding="3" Font-Size="X-Small" BackColor="White" BorderColor="#3399FF" BorderWidth="1px" BorderStyle="None" GridLines="Horizontal" PagerSettings-Mode="NumericFirstLast" HeaderStyle-BackColor="#269AE9" AutoGenerateColumns="False">
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Update">
<ItemStyle BackColor="#99ccff" />
</asp:CommandField>
<asp:BoundField DataField="AssetID" HeaderText="AID" ReadOnly="True" SortExpression="AssetID"></asp:BoundField>
<asp:BoundField DataField="AssetType" HeaderText="Asset Type" SortExpression="AssetType">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetName" HeaderText="Asset Name" SortExpression="AssetName"></asp:BoundField>
<asp:BoundField DataField="AssetShortDesc" HeaderText="Short Desc" SortExpression="AssetShortDesc">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetLongDesc" HeaderText="Long Desc" SortExpression="AssetLongDesc"></asp:BoundField>
<asp:BoundField DataField="AssetAddNotes" HeaderText="Add Notes" SortExpression="AssetAddNotes">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetManuf" HeaderText="Manufacturer" SortExpression="AssetManuf"></asp:BoundField>
<asp:BoundField DataField="AssetModel" HeaderText="Model" SortExpression="AssetModel">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetTag" HeaderText="Asset Tag" SortExpression="AssetTag"></asp:BoundField>
<asp:BoundField DataField="AssetSerialNum" HeaderText="Serial Num" SortExpression="AssetSerialNum">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetAcqDate" HeaderText="Date Acquired" SortExpression="AssetAcqDate"></asp:BoundField>
<asp:BoundField DataField="AssetDTAssetID" HeaderText="Deltek Asset ID" SortExpression="AssetDTAssetID">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetLocGrp" HeaderText="Loc Grp" SortExpression="AssetLocGrp"></asp:BoundField>
<asp:BoundField DataField="AssetLoc1" HeaderText="Loc 1" SortExpression="AssetLoc1">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetLoc2" HeaderText="Loc 2" SortExpression="AssetLoc2"></asp:BoundField>
<asp:BoundField DataField="AssetLoc3" HeaderText="Loc 3" SortExpression="AssetLoc3">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetParent" HeaderText="Asset Parent" SortExpression="AssetParent"></asp:BoundField>
<asp:BoundField DataField="AssetStatus" HeaderText="Status" SortExpression="AssetStatus">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetPropType" HeaderText="Property Type" SortExpression="AssetPropType"></asp:BoundField>
<asp:BoundField DataField="AssetPrimUser" HeaderText="Primary User" SortExpression="AssetPrimUser">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetEntered" HeaderText="Entered" SortExpression="AssetEntered"></asp:BoundField>
<asp:BoundField DataField="AssetEnteredBy" HeaderText="Entered By" SortExpression="AssetEnteredBy">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetOwner" HeaderText="Asset Owner" SortExpression="AssetOwner"></asp:BoundField>
<asp:BoundField DataField="AssetCompany" HeaderText="Company" SortExpression="AssetCompany">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetPriIPAddr" HeaderText="Primary IP Addr" SortExpression="AssetPriIPAddr"></asp:BoundField>
<asp:BoundField DataField="AssetPriMACAddr" HeaderText="Primary MAC Addr" SortExpression="AssetPriMACAddr">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetPriOS" HeaderText="Primary OS" SortExpression="AssetPriOS"></asp:BoundField>
<asp:BoundField DataField="AssetPriOSSP" HeaderText="Primary OS SP" SortExpression="AssetPriOSSP">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetNotes" HeaderText="Asset Notes" SortExpression="AssetNotes"></asp:BoundField>
<asp:BoundField DataField="AssetAdminGrp" HeaderText="Admin Grp" SortExpression="AssetAdminGrp">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetOrgID" HeaderText="Organization ID" SortExpression="AssetOrgID"></asp:BoundField>
<asp:BoundField DataField="AssetOperType" HeaderText="Oper Type" SortExpression="AssetOperType">
<ItemStyle BackColor="#CCCCCC"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="AssetOperStatus" HeaderText="Oper Status" SortExpression="AssetOperStatus"></asp:BoundField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066"></FooterStyle>
<HeaderStyle BackColor="#99ccff" Font-Bold="True" ForeColor="Black"></HeaderStyle>
<PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White"></PagerStyle>
<RowStyle ForeColor="#000066"></RowStyle>
<SelectedRowStyle BackColor="#669999" ForeColor="White" Font-Bold="True"></SelectedRowStyle>
<SortedAscendingCellStyle BackColor="#F1F1F1"></SortedAscendingCellStyle>
<SortedAscendingHeaderStyle BackColor="#007DBB"></SortedAscendingHeaderStyle>
<SortedDescendingCellStyle BackColor="#CAC9C9"></SortedDescendingCellStyle>
<SortedDescendingHeaderStyle BackColor="#66ccff"></SortedDescendingHeaderStyle>
</asp:GridView>
<asp:SqlDataSource ID="InventoryList" runat="server" CancelSelectOnNullParameter="false" ConnectionString='<%$ ConnectionStrings:CMDB_testConnectionString %>' SelectCommand="SELECT AssetID, AssetType, AssetName, AssetShortDesc, AssetLongDesc, AssetAddNotes, AssetManuf, AssetModel, AssetTag, AssetSerialNum, AssetAcqDate, AssetDTAssetID, AssetLocGrp, AssetLoc1, AssetLoc2, AssetLoc3, AssetParent, AssetStatus, AssetPropType, AssetPrimUser, AssetEntered, AssetEnteredBy, AssetOwner, AssetCompany, AssetPriIPAddr, AssetPriMACAddr, AssetPriOS, AssetPriOSSP, AssetNotes, AssetAdminGrp, AssetOrgID, AssetOperType, AssetOperStatus FROM cmdbv_Assets_CInTrac WHERE (AssetID = ISNULL(@AssetID, AssetID)) AND (AssetName = ISNULL(@AssetName, AssetName)) AND (AssetType = ISNULL(@AssetType, AssetType)) AND (AssetManuf = ISNULL(@AssetManuf, AssetManuf)) AND (AssetModel = ISNULL(@AssetModel, AssetModel)) AND (AssetTag = ISNULL(@AssetTag, AssetTag)) AND (AssetSerialNum = ISNULL(@AssetSerialNum, AssetSerialNum)) AND (AssetDTAssetID = ISNULL(@AssetDTAssetID, AssetDTAssetID)) AND (AssetLocGrp = ISNULL(@AssetLocGrp, AssetLocGrp)) AND (AssetLongDesc = ISNULL(@AssetLongDesc, AssetLongDesc)) AND (AssetOrgID = ISNULL(@AssetOrgID, AssetOrgID)) AND (AssetPriIPAddr = ISNULL(@AssetPriIPAddr, AssetPriIPAddr)) AND (AssetStatus = ISNULL(@AssetStatus, AssetStatus))">
<SelectParameters>
<asp:ControlParameter Name="AssetID" ControlID="AssetIDTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetName" ControlID="AssetNameTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetType" ControlID="AssetTypeTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetManuf" ControlID="AssetManufTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetModel" ControlID="AssetModelTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetTag" ControlID="AssetTagTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetSerialNum" ControlID="AssetSerialNumTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetDTAssetID" ControlID="AssetDTAssetIDTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetLocGrp" ControlID="AssetLocGrpTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetLongDesc" ControlID="AssetLongDescTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetOrgID" ControlID="AssetOrgIDTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetPriIPAddr" ControlID="AssetPriIPAddrTbx" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter Name="AssetStatus" ControlID="AssetStatusTbx" Type="String" ConvertEmptyStringToNull="true" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
希望有人有一些见解,因为我希望能够对这些文本框实施 LIKE。
【问题讨论】:
-
删除 LINQ 标记,因为此问题中没有任何内容与 LINQ 相关。
标签: asp.net gridview sqldatasource