Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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> 


What I have tried:

I have found nothing that explains the proper PropertyName for the filter parameter.
Posted
Updated 6-Jul-18 18:20pm

1 solution

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 $0.2.
 
Share this answer
 
Comments
BobbyStrain 7-Jul-18 20:25pm    
Vincent, Thanks for the reply. I have only 3 datasources, so all the code is not too overwhelming. And I don't do much. I found a means to make it work by adding a textbox and filtering on the textbox text. I have a similar desktop application for which I do use datasets. It works smoothly using queries.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900