简体   繁体   中英

Change select query in SqlDataSource from code behind

Ive got 2 RadGridViews - Telerik. I use sqlDataSource for each one. In first Ive got customers and in the second Ive got orders.

First grid is multiselect. I can select more than one row. The key functionality that I would like to have is that each time user changes selection if first grid then in the second one should be all orders where iserId is in selected user ids from the first one.

There is an event:

protected void GvUsers_OnSelectedIndexChanged(object sender, EventArgs e)

in this event I would like to modify select command on my orders dataSource and execute it.

How can I do that ?

dsOrders.SelectCommand =
        select ...

    GvOrders.DataSource = dsOrders.Select(DataSourceSelectArguments.Empty);

    GvUserOrders.DataBind();
    GvUserOrders.Rebind();

this doesnt work, using profiler I dont even see Query made to the database

Thanks for any help

What do you mean how do I do that? How did you do it initially? On the selected index changed event, create an sql command object, with a new select, execute the query, assign it to a dataset / datatable / reader . Then assign that object to the gridview's datasource and databind() it.

The point is you initially loaded the grid view. To change the contents of the gridview again follow that same procedure just assign a new sqlcommand object (pointing to a different SQL Select statement) to the gridview's datasource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM