Using wildcards with a LinqDataSource

前端 未结 2 551
醉话见心
醉话见心 2021-01-07 00:36

I currently have a LinqDataSource on an ASP.NET page which is used as the data source for a FormView. I need to dynamically alter the where clause based on para

相关标签:
2条回答
  • 2021-01-07 01:15

    Please try url decode Request.QueryString[key]

    Example:

    HttpUtility.UrlDecode(Request.QueryString[key]);
    
    0 讨论(0)
  • 2021-01-07 01:25

    I have finally managed to get this figured out. Thanks to a class from this post, I am able to to use the LinqDataSource_Selecting event and filter my data successfully with wildcards working using this code:

    protected void ldsData_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        var result = db.INSTRUMENT_LOOP_DESCRIPTIONs.AsQueryable();
    
        foreach (string key in Request.QueryString.Keys)
        {
            if (Request.QueryString[key].Trim() != "")
            {
                result = result.WhereLike(key, Request.QueryString[key].Replace("?", "_").Replace("*", "%"));
            }
        }
    
        e.Result = result;
    }
    
    0 讨论(0)
提交回复
热议问题