Skip to content Skip to sidebar Skip to footer

Asp.net Setting Parameter For Sqldatasource Programatically Does Not Work For Postback

I want to set a parameter for a SqlDataSource programmatically as described in Step 5 at http://www.asp.net/data-access/tutorials/using-parameterized-queries-with-the-sqldatasource

Solution 1:

You may need an explict databaind on postbacks:

if (Page.IsPostBack)
{
    grid.DataBind();
}

Should do it.

Solution 2:

C#

SqlDataSource1.SelectParameters["Where_Clause"] = newParameter() { Name = "Where_Clause", DefaultValue = "WHERE m.Id = 1" };

Greedy Networks.

Post a Comment for "Asp.net Setting Parameter For Sqldatasource Programatically Does Not Work For Postback"