【问题标题】:is there a way to have a sqldatasource filter when asked but default to select *?有没有办法在询问时使用 sqldatasource 过滤器但默认选择 *?
【发布时间】:2012-02-25 01:55:59
【问题描述】:

我有一个绑定到 sqldatasource 的列表视图。我知道如何通过将 sqldatasource 绑定到控件值来过滤结果,但是我希望 sqldatasource 在控件中没有任何内容被选中时选择全部。我怎么做?

请记住,我对列表视图进行了分页,因为我知道这可能会给简单的解决方案带来问题。例如,如果我使用 !Page.IsPostback 处理初始加载,列表的初始内容很好,但是如果我单击寻呼机控件中的页面,它将使用过滤器下拉列表中选择的任何名称重新加载网格.

【问题讨论】:

    标签: asp.net listview sqldatasource


    【解决方案1】:

    您可以使用 SqlDataSource Selecting 事件在选择命令执行之前修改参数。

    C#

       protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            if (DropDownList1.SelectedValue != "thisValue")
            {
                // Do what you want with the datasource here. In the example I change the
                // value of a parameter
                e.Command.Parameters["@parameter"].Value = DropDownList1.SelectedValue;
            }
        }
    

    VB

    Protected Sub SqlDataSource1_Selecting(sender As Object, e As SqlDataSourceSelectingEventArgs)
        If DropDownList1.SelectedValue <> "thisValue" Then
            e.Command.Parameters("@parameter").Value = DropDownList1.SelectedValue
        End If
    End Sub
    

    这是 SqlDataSource.Selecting Event 上的 MSDN 文章

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多