如何包含';all';asp.net中的搜索选项

本文关键字:搜索 选项 all 何包含 asp net | 更新日期: 2023-09-27 18:19:35

我正在尝试为我的aspx页面添加ALL搜索函数。问题是我不知道该怎么做。这是我所能做到的,下面是代码:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        DataTable dtTransactionCategory = clsTransactionCategory.GetTransactionCategory(Helper.LogID, Helper.OrgID, Helper.SiteID, 0, string.Empty);
        ddlTransactionCategoryDesc.DataSource = dtTransactionCategory;
        ddlTransactionCategoryDesc.DataTextField = "TransactionCategoryDesc";
        ddlTransactionCategoryDesc.DataValueField = "TransactionCategoryID";
        ddlTransactionCategoryDesc.DataBind();
        ddlTransactionCategoryDesc.Items.Insert(0, new ListItem("All"));
        ddlTransactionCategoryInput.DataSource = dtTransactionCategory;
        ddlTransactionCategoryInput.DataTextField = "TransactionCategoryDesc";
        ddlTransactionCategoryInput.DataValueField = "TransactionCategoryID";
        ddlTransactionCategoryInput.DataBind();
        logID = CommonFunctions.StringToInt(Session[Constants.SessionLogID].ToString());
        orgID = 1;
        siteID = 1;
        ddlTransactionCategoryDesc.SelectedValue = Convert.ToString(ddlTransactionCategoryDesc);
        txtTransactionDesc.Text = string.Empty;
        BindData();
    }
}

以及存储过程,如果需要:

ALTER PROC [dbo].[spMSTransaction_Get] 
@OrgID INT,
@SiteID INT,
@TransactionCategoryID INT,
@TransactionCategoryDesc varchar (300),
@TransactionDesc varchar(300)
AS
    SET NOCOUNT ON
    SELECT mst.[OrgID], 
            mst.[SiteID], 
            mst.[TransactionID],
            mst.[TransactionCategoryID], 
            mstc.[TransactionCategoryDesc],
            mst.[TransactionDesc], 
            mst.[IsActive], 
            [master].dbo.fnConvertUTCToLocalTimeZone (mst.[CreatedDate]) as [CreatedDate],
            mst.[CreatedBy], 
            [master].dbo.fnConvertUTCToLocalTimeZone (mst.[ModifiedDate]) as [ModifiedDate],  
            mst.[ModifiedBy] 
    FROM [dbo].[MSTransaction] AS mst
    INNER JOIN [dbo].[MSTransactionCategory] AS mstc
    ON mst.OrgID = mstc.OrgID  AND mst.SiteID = mstc.SiteID AND mst.TransactionCategoryID = mstc.TransactionCategoryID
    WHERE (mst.[OrgID] = @OrgID OR @OrgID = 0) 
            AND (mst.[SiteID] = @SiteID OR @SiteID = 0) 
            AND (mst.[TransactionCategoryID] = @TransactionCategoryID OR @TransactionCategoryID = 0)
            AND (mst.[TransactionDesc] LIKE '%' + @TransactionDesc + '%')
            AND (mst.[isActive] = 1)

我已经放了ddlTransactionCategoryDesc.Items.Insert(0, new ListItem("All"));,但它返回了一个错误:

输入字符串的格式不正确。

知道我需要修复什么以及应该做什么来实现ALL搜索功能吗?谢谢

如何包含';all';asp.net中的搜索选项

根据存储过程,@TransactionCategoryIDINT。添加ALL列表需要使用以下内容:

ddlTransactionCategoryDesc.Items.Insert(0, new ListItem("All", "0"));

这将使ALL的值成为INT。您当前拥有的ListItem("All")会自动将Value的类型更改为字符串。执行后检查下拉列表,它会将值显示为All,但不能传递到存储过程所需的INT中。