【发布时间】:2016-06-23 20:51:42
【问题描述】:
我很高兴看到有人在哪里用 sqldatasource 做我想做的事,所以我根据我的目的对其进行了调整,但是虽然我可以毫无错误地运行它,但无论是否在文本中输入数据,我也没有得到任何数据盒子。
这是一个链接到启发我的线程 Reference link for what I used: 你会注意到巴黎的答案是我改编的:
我已经尝试了两种技术,结果相同,所以我真的很困惑。 这是我的aspx代码:
<asp:SqlDataSource ID="InventoryList" runat="server" 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 [cmdb_assets]
WHERE [AssetName] = CASE @AssetName THEN [AssetName] END AND [AssetType] = CASE @AssetType THEN [AssetType] END AND [AssetManuf] = CASE @AssetManuf THEN [AssetManuf END AND [AssetModel] = CASE @AssetModel THEN [AssetModel] END">
接着是:
<SelectParameters>
<asp:ControlParameter Name="AssetName" ControlID="AssetNameTbx" Type="String" />
<asp:ControlParameter Name="AssetType" ControlID="AssetTypeTbx" Type="String" />
<asp:ControlParameter Name="AssetManuf" ControlID="AssetManufTbx" Type="String" />
<asp:ControlParameter Name="AssetModel" ControlID="AssetModelTbx" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
正如第一个线程响应者所追求的那样,我想要做的是允许在一个或多个文本框中输入信息,然后通过此选择将结果过滤到我的网格视图中。 想法? 肯...
我想我会提供我上面使用的两个示例的结果的输出,以及我刚刚尝试由另一个论坛成员在 2014 年测试提供的最新结果,该成员也做了相同的 nodata 返回结果。只是为了看结果。真的没有价值,但仍然。 肯... 数据源最终是什么:
<asp:SqlDataSource ID="InventoryList" runat="server" 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)" CancelSelectOnNullParameter="false">
【问题讨论】:
-
所以,我很清楚,您基本上有一个包含多个字段的网格,并且您有一些文本框,如果它们有值则应该过滤,如果没有则不过滤。对吗?
-
您在
[AssetManuf中没有];是复制粘贴错误吗? -
@techspider 复制粘贴错误更正 ] 在代码中。是的。
-
是的,目标是提供一系列文本框,这些文本框可能会或可能不会填充各种字段的过滤文本。如果留空,则应将其视为有效 * 对于该列允许任何内容通过而不是过滤任何内容。因此,如果您在没有文本的情况下将其拉出,您将看到表中的所有记录。如果您在“资产类型”中输入笔记本电脑,您将只获得笔记本电脑的列表。如果您随后将 HP 添加到 Asset Mfg 框中,您将只能获得 HP 笔记本电脑。