0

I have a sqldatascource that I need to pass null values to it and then use the selectcommand specified by a stored procedure and then using the result query to populate a gridview on the page load

notes: I tried the stored procedure on sql server managment studio and its working fine

I alread specified sqldatascource on for gridview1 in the page design view

I tried this code but the gridview still shows empty

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();
    }
4

1 回答 1

0

我认为 usingnull不代表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();
        }
    }
于 2013-05-07T05:46:40.430 回答