0

我正在尝试ALL为我的 aspx 页面添加搜索功能。问题是我不知道如何正确地做到这一点。这是我能做到的,这是背后的代码:

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搜索功能吗?谢谢。

4

1 回答 1

1

根据您的存储过程,@TransactionCategoryID是一个INT. 添加ALL列表将需要您使用以下内容:

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

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

于 2013-06-24T09:32:08.630 回答