Search code examples
c#.netgridviewdatasourcecode-behind

Gridview rebind data with new parameters


OK, so I need to change the values stored in my gridview based on input from user. I used to filter it 100% with javascript, but it turns out that it needs to be paged, so that wont work. Instead, I have to call on the datasource again, but with parameters from the textbox.

I've figured out that I must call a function in code behind and from there call DataBind(), but I dont even know where to start. Please help

I know that I ought to post some code to show that I've made an effort, but I really dont have anything to show. i guess it would be something along these lines?:

protected void ReBind(string sParameter)
{
    SqlDataSource.SelectParameters.Add("parameterName", sParameter);
    myGridView.DataBind();
}

But obviously I'm fumbling in the dark here.


Solution

  • Turns out that this worked out fine:

    protected void ReBind(String sParameter)
    {
       SqlDataSource.SelectParameters.Remove(SqlDataSource.SelectParameters["parameterName"]);
       SqlDataSource.SelectParameters.Add("parameterName", sParameter);
       myGridView.DataBind();
    }