Last post Oct 08, 2020 02:05 PM by Peter Cong
Oct 07, 2020 10:13 PM|Peter Cong|LINK
Hi, I am converting a web form VB web application to MVC web with razor view as front end.
There is a Search function in web form to search an active directory and add the search result to a ListBox control. here is the ListBox control of web form.
<asp:ListBox ID="lstSearchResults" runat="server" Height="99px" Width="335px" meta:resourcekey="lstSearchResultsResource2" style="left: 5px; position: absolute; top: 92px" AppendDataBoundItems="True" ></asp:ListBox>
here is the backend VB codes
// tblSearchResults below is a datatable object returned from another function with the correct number of dataDim dvSearchResults As DataView = New DataView(tblSearchResults, "", "distinguishedname", DataViewRowState.CurrentRows)
dvSearchResults.RowFilter = "Email <> 'No Value Entered'"
.DataSource = dvSearchResults
.DataTextField = "mailnickname" '"Email"
.DataValueField = "distinguishedname"
lblResults.Visible = True
lblResults.Text = GetLocalResourceObject("ResultsFound") & " - " & .Items.Count
Here is the converted C# codes of MVC,
//tblSearchResults is the same datatable defined and returns correct data
dvSearchResults = new DataView(tblSearchResults, "", "distinguishedname", DataViewRowState.CurrentRows);
dvSearchResults.RowFilter = "Email <> 'No Value Entered'";
recordCount = dvSearchResults.Count;
The above MVC results returns to a partial view shows on razor view.
Question: The search result works for most cases, but for some data entered returns nothing. I am wondering if I need to change the codes for converting the ListBox control to partial view. The only thing I am thinking is that the ListBox is binded with
Datasource, but partial view is binded with datatable, anything wrong with my design? thanks a lot,
Oct 08, 2020 03:12 AM|YihuiSun|LINK
Hi Peter Cong,
Oct 08, 2020 02:05 PM|Peter Cong|LINK
Hi Peter Cong,
If all the values in dvSearchResults are "No Value Entered", the result you get is empty.You need to check the value of the data that needs to be filtered.
If you want to return the results of a particular query on the data, as opposed to providing a dynamic view of a subset of the data, use the
Find or FindRows methods of the DataView to achieve best performance rather than setting the
Thank you so much for your help, after more testing, I found that the only issue is the case of when search result is one record. In the webform vb codes, I got one record which is correct, but in the new mvc c# codes, I got nothing.
I suspect it is the filer problem, I should do a check for the one record search result. So if dvSearchResults.count = 1, then don't do the filter, otherwise, do the filter.
Do you agree?