Hello, I have a news table which contains the dates and id of a particular news entry and a child table with the actual newstexts in a particular language that reference a news entry in the parents table:
News(ID, DATE etc.) --> Newsdetails(ID, NEWS_ID (FK(NEWS), NEWS_TEXT, LANGUAGE)
a perfect situation for a whdg. Now I would like to be able to search for detail records (in particular the News_text field) and filter down the grid to show only the rows with childs that contain the searchtext. For that I tried to join the parent records with the child and expose a selectParameter
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCT mas.ID FROM NEWS mas LEFT OUTER JOIN NEWSDETAILS det ON mas.ID = det.NEWS_ID WHERE det.NEWS_TEXT like '%'+:searchinput+'%'" EnableViewState="False">
<SelectParameters>
<asp:ControlParameter ControlID="txtSearch" Name="searchinput" PropertyName="Text" />
SelectParameters>
asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT ID, NEWS_ID, LANGUAGE_ID, NEWS_TEXT FROM NEWSDETAILS" EnableViewState="False">
<ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource1" runat="server">
<DataViews>
<ig:DataView ID="SqlDataSource1_DefaultView" DataMember="DefaultView" DataSourceID="SqlDataSource1" />
<ig:DataView ID="SqlDataSource2_DefaultView" DataMember="DefaultView" DataSourceID="SqlDataSource2" />
DataViews>
<DataRelations>
<ig:DataRelation ChildColumns="NEWS_ID" ChildDataViewID="SqlDataSource2_DefaultView" ParentColumns="ID" ParentDataViewID="SqlDataSource1_DefaultView" />
DataRelations>
ig:WebHierarchicalDataSource>
And a Standard WHDG connected to the Hierarchical Source. If I remove the SelectParameters, it does work good. However, I would like to be able to have a global search field, so I can enter a text and the SQLDataSource1 should be filtered to all records which contain this searchtext.
So, as soon as there is a SelectParameters I get a "Object reference not set to an instance of an object." exception. If I connect a normal WebDataGrid to the SqlDataSource1, it does work fine. So the Problem only appears in combination with the WebHierarchicalDataSource.
What can I do to solve the Problem?
Hello,
Thank you for using our forum!
However I was not able to reproduce the behaviour that you're seeing on your side. I have attached the sample project I used to test this. Please test this project on your side; whether or not it works correctly may help indicate the nature of this issue.
If this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.
Please let me know if I can provide any further assistance.
Hi Nadia, thanks, I was able to run your example. It does work, however, when adding a button to postback and change the search text,
I sometimes get the following behaviour:
- Enter a category that doesn't exist and click search. Then search for something that exists (for example: Beverages), click the + to open a few parent rows.
Now from time to time, the grid shows no child rows (even though they exist) or it even makes a postback and refreshes the whole page.
Do you also get this problem?
It gets even more crazy when adding sorting behaviour for example.
Hi Marc,
I was not able to reproduce this behavior.
Have you set the DataKeyFields in root and child band? When you do not set them correct (for example there are duplicate DataKeyFields) the child items for this rows cannot be opened.
Can you send me an isolated sample to can investigate you issue?
Hello Nadia
Please find an isolated example in the attachment. It's basically your example changed a little bit to match my Scenario:
- Category 1
---- Product 1
---- Product 2
-Category 2
-----Product 3
.....
And I changed the InitialBindDepth (which you had set to 1) back to 0 as I have lots of childs which will result in bad Performance if I use BindDepth of 1. And this might actually cause the Problem:
Try searching for different terms, (I usually use "Test" (no results), "Mix" (2 categories) and "" (All results) and expand some of the categories before searching for the next word
Maybe you have to perform a few searches before the problem appears. Usually the expanded grid will either be empty or the whole page will reload instead of an asynchronous call. I also once got the ""No child grid script descriptors are available" exception.
I'm using the version=15.1.20151.2123
Please let me know if you can reproduce the error. Thank you!
Hello Mark,
I want to thank you for your patience on this.
This incorrect behavior is happening because of the load on demand functionality, and by saying this I mean that if you set InitialDataBindDepth to be 1 or -1, the issue will no longer persist.
Basically, when you expand a row for a first time, it is rendered correctly, the sample is using load on demand (default InitialDataBindDepth value is 0). After we remove the value "mix" ftom the textbox, the grid is doing a rerender, because its data source is changed. On this rerendering, the Grid is checking its load on demand state and, because it is set to 0 (to load childs on demand) the expanded row is hidden. This is a scenario that is supposted to work this way. So in order the child grid to be populated okay, InitialDataBindDepth should be set to a value suitable for the scenario (1 or -1).
In general, if you want to perform some kind of filtering of the data, do not filter the data source directly, because this is considered as assign of a new data source, and the Grid is confused in some cases.
If you want to perform data filtering, just use our Filtering behavior.