根据gridview选择过滤数据源 [英] Filter datasource based on gridview selection

查看:100
本文介绍了根据gridview选择过滤数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用asp.net VB构建的网页。数据库是一个有家庭成员的数据库。有三个数据绑定控件; gridview和2 detailsview。除了使用过滤器绑定到数据源的一个详细信息视图外,它们正在工作。我想在datagrid视图的第一个详细信息视图中显示信息。这很好用。我希望第二个detailview在gridview中显示选择的父信息。父母和孩子在同一张桌子里。父ID位于不是键的字段中。我从一个示例编码数据源,但detailsview显示所选行的信息,而不是父。我可以更改代码以将filterexpression设置为ID = 4,详细信息视图显示第4行的信息。

我相信我没有正确设置FilterParameter参数。我在参数中使用什么作为PropertyName =从所选行parentid字段中获取值?使用SelectedValue返回gridview ID列,这是键。



I have a web page built with asp.net VB. The database is one with family members. There are three databound controls; gridview and 2 detailsview. They are working except for one details view which is bound to a datasource using a filter. I want to display information in the first detailsview of the selection from the datagrid view. This works OK. I want the second detailsview to display the parent information for the selection in the gridview. The parent and child are in the same table. The parent ID is in a field that is not a key. I coded the datasource from an example, but the detailsview displays the information for the selected row, not the parent. I can change the code to set the filterexpression to ID=4, for example and the details view displays the information for row 4.
I believe that I don't have the FilterParameter parameter properly set. What do I use as the PropertyName= in the parameter to get the value from the selected row parentid field? Using SelectedValue returns the gridview ID column which is the key.

<asp:SqlDataSource ID="SqlDataSource4" runat="server" 
        SelectCommand="SELECT ID, Last_Name, First_Name FROM contacts"
        FilterExpression="ID='{0}'" 
         ConnectionString="<%$ ConnectionStrings:mystrainfamilyConnectionString %>"
        ProviderName="<%$ ConnectionStrings:mystrainfamilyConnectionString.ProviderName %>" >    
            <FilterParameters>
                <asp:ControlParameter Name="ID" ControlID="GridView1" DefaultValue="1"  
                    PropertyName="SelectedValue" />
            </FilterParameters>
    </asp:SqlDataSource> 





我的尝试:



我没有找到解释filter参数的正确PropertyName的任何内容。



What I have tried:

I have found nothing that explains the proper PropertyName for the filter parameter.

推荐答案

ConnectionStrings:mystrainfamilyConnectionString%>
ProviderName =<%
ConnectionStrings:mystrainfamilyConnectionString %>" ProviderName="<%


ConnectionStrings:mystrainfamilyConnectionString.ProviderName%>>
< FilterParameters>
< asp:ControlParameter Name =IDControlID =GridView1DefaultValue = 1
PropertyName =SelectedValue/>
< / FilterParameters>
< / asp:SqlDataSource>
ConnectionStrings:mystrainfamilyConnectionString.ProviderName %>" > <FilterParameters> <asp:ControlParameter Name="ID" ControlID="GridView1" DefaultValue="1" PropertyName="SelectedValue" /> </FilterParameters> </asp:SqlDataSource>





我尝试了什么:



我没有找到任何解释filter参数的正确PropertyName的内容。



What I have tried:

I have found nothing that explains the proper PropertyName for the filter parameter.






我还没有真正使用过Wizard DataSources 对于复杂的场景,我可以真的可以直接解决你现在所拥有的问题。



如果我是你,我会使用 ADO.NET 方式 DataSet / DataTable 。向导数据源如 SqlDataSource 是好的,但对我来说,我更喜欢使用 DataSets SqlCommands - 我称它为硬编码数据集,因为我可以在那里编写自己的逻辑并执行类似排序过滤的内容 SqlDataSource 很好,如果要生成一个简单的查询,可能是首选。但是当谈到交织在一起/复杂的查询时(就像你现在所拥有的那样),它往往变得复杂和混乱。 SqlDataSource 在大量代码块的情况下也难以维护,我们必须为不同的数据控件生成umpteen DataSources 。在硬编码的sql数据绑定的情况下,我们可以重复使用代码而不会根据需要在这里和那里更改基本查询,并且维护它也容易得多。



如果您不习惯使用Sql查询,您还可以使用ORM,例如 LINQ to SQL 实体框架作为数据控件的数据源。



只是我的
Hi,

I haven't really used Wizard DataSources for complex scenarios, so I can't really give a straight solution to what you are having now.

If I were you I would use the ADO.NET way with DataSets/DataTable. Wizard DataSource such as SqlDataSource are good, but for me I would prefer using DataSets with SqlCommands - I called it the hard-coded dataset because I can write my own logic there and do stuff like Sorting and Filtering. SqlDataSource is good and could be preferred if a simple query is to be generated. But it tends to get complicated and confusing when it comes to intertwined/complex queries (just like what you are having now). SqlDataSource is also hard to maintain in case of huge blocks of code and we have to generate umpteen DataSources for different data controls. Where as in the case of hard-coded sql databind, we can reuse the code without any hiccups changing the basic query here and there according to requirements and It is also a lot easier to maintain it.

If you are not comfortable working with Sql queries, you could also use an ORM such as LINQ to SQL or Entity Framework as your data source for your data controls.

Just my


这篇关于根据gridview选择过滤数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆