更新我的 Gridview 搜索框以使用 LIKE 而不是“= 或 null”
Updating my Gridview Search boxes to use LIKE instead of '= or null'
我目前有一个 gridview,其顶部有文本框,用户可以将其留空(在这种情况下,将返回 table 中的所有记录),或者用户可以提供与相应信息完全匹配的信息文本框中 table 中的字段将结果限制为仅那些记录的行具有相应字段中文本框的内容。我有 14 个这样的文本框,它们的任意组合都可以填充或闲置,为用户需要的记录创建过滤器。
但我想将其推进下一步。而不是要求 'exact match' 我宁愿做一个喜欢。本质上,如果我提供单词 dog,我希望 select 有效地充当 %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。
您将需要 IS NULL OR LIKE
在 where 子句中。
SelectCommand="SELECT AssetID, ..., AssetOperStatus
FROM cmdbv_Assets_CInTrac
WHERE (@AssetID IS NULL OR AssetID LIKE '%' + @AssetID + '%') AND
...
(@AssetStatus IS NULL OR AssetStatus LIKE '%' + @AssetStatus + '%')"
来自胜利:
(RTRIM(LTRIM(ISNULL(@AssetID, ''))) = '' OR AssetID LIKE '%' + @AssetID + '%')
我目前有一个 gridview,其顶部有文本框,用户可以将其留空(在这种情况下,将返回 table 中的所有记录),或者用户可以提供与相应信息完全匹配的信息文本框中 table 中的字段将结果限制为仅那些记录的行具有相应字段中文本框的内容。我有 14 个这样的文本框,它们的任意组合都可以填充或闲置,为用户需要的记录创建过滤器。
但我想将其推进下一步。而不是要求 'exact match' 我宁愿做一个喜欢。本质上,如果我提供单词 dog,我希望 select 有效地充当 %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。
您将需要 IS NULL OR LIKE
在 where 子句中。
SelectCommand="SELECT AssetID, ..., AssetOperStatus
FROM cmdbv_Assets_CInTrac
WHERE (@AssetID IS NULL OR AssetID LIKE '%' + @AssetID + '%') AND
...
(@AssetStatus IS NULL OR AssetStatus LIKE '%' + @AssetStatus + '%')"
来自胜利: (RTRIM(LTRIM(ISNULL(@AssetID, ''))) = '' OR AssetID LIKE '%' + @AssetID + '%')