【问题标题】:using selectcommand on code behind with gridview在 gridview 后面的代码上使用 selectcommand
【发布时间】:2013-05-07 13:46:40
【问题描述】:

我有一个 sqldatasource,我需要将空值传递给它,然后使用存储过程指定的选择命令,然后使用结果查询在页面加载时填充网格视图

注意:我在 sql server managment studio 上尝试了存储过程,它工作正常

我已经在页面设计视图中为 gridview1 指定了 sqldatasource

我试过这段代码,但gridview仍然显示为空

protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataSource1.SelectParameters["location"].DefaultValue = null;
        SqlDataSource1.SelectParameters["time"].DefaultValue = null;
        SqlDataSource1.SelectParameters["date"].DefaultValue = null;
        SqlDataSource1.DataBind();
        GridView1.DataBind();
    }

【问题讨论】:

    标签: asp.net gridview code-behind sqldatasource selectcommand


    【解决方案1】:

    我认为使用null 并不代表database NULL。 这可能有效

    protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
              SqlDataSource1.SelectParameters["location"].DefaultValue = System.DbNull.Value;
              SqlDataSource1.SelectParameters["time"].DefaultValue = System.DbNull.Value;
              SqlDataSource1.SelectParameters["date"].DefaultValue = System.DbNull.Value;
              SqlDataSource1.DataBind();
              GridView1.DataBind();
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-13
      • 2012-02-16
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多