locked
Refreshing SqlDataSource parameter values in ASP.Net RRS feed

  • Question

  • I'm coding a rather basic ASP.Net page that has the following controls:

    DropDownList

    SqlDataSource

    GridView

    The SqlDataSource has a Select statement with one parameter, bound to the value of the DropDownList.

    The GridView is bound to the SqlDataSource, and displays the result of its Select statement.

    This all works as expected- but the problem is I'd like to set the value of the DropDownList from a session variable when the page loads, like so:

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int? projectIndex = (int?)Session["ProjectId"];
                ProjectId.SelectedIndex = projectIndex ?? 0;
            }
        }

    This also works fine- the session variable is used to set the selected index of the DropDownList. The problem is that the parameter used by the data source isn't also updated, and calling DataBind() on either the data source or the grid doesn't pick up the DropDownList's new value.

    The question is: How do I tell the data source or the grid view to pick up the new value before calling DataBind again to update the contents of the grid?

       

    • Moved by Min Zhu Wednesday, June 6, 2012 4:59 AM (From:ADO.NET Managed Providers)
    Tuesday, May 8, 2012 10:05 PM

All replies