简体   繁体   English

从后面的代码更改SqlDataSource中的选择查询

[英]Change select query in SqlDataSource from code behind

Ive got 2 RadGridViews - Telerik. 我有2个RadGridViews-Telerik。 I use sqlDataSource for each one. 我为每个使用sqlDataSource。 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. 我想拥有的关键功能是,每次用户更改选择时,如果第一个网格位于第二个网格中,则应该是iserId在第一个网格的选定用户ID中的所有顺序。

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. 在这种情况下,我想修改订单dataSource上的select命令并执行它。

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 . 在选定的索引更改事件上,创建一个sql命令对象,并进行新的选择,执行查询,并将其分配给dataset / datatable / reader Then assign that object to the gridview's datasource and databind() it. 然后将该对象分配给gridview的datasource并对其进行databind()

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. 要再次更改gridview的内容,请遵循相同的过程,只需将新的sqlcommand对象(指向其他SQL Select语句)分配给gridview的数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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