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();
    }
Scarnet
  • 738
  • 2
  • 11
  • 36

1 Answers1

0

I think using null does not represent a database NULL. This might work

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();
        }
    }
Zo Has
  • 12,599
  • 22
  • 87
  • 149