Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Search in Grid View by Scanning?
Message
De
14/12/2015 12:54:06
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01628904
Message ID:
01628911
Vues:
30
J'aime (1)
>>>>Hi,
>>>>
>>>>I have ASP.NET Grid View on ASPX page bound to a dataset/table. I need to find a value of one column by the value of another column. For example, say Grid View has columns Order_no and Customer_Name. I have the customer name "ABC" and need to find the Order_no corresponding to this Customer; basically find this row. I found examples online of scanning through the Grid View. Is this the only approach? Or you can actually Search for the desired row?
>>>>
>>>>TIA
>>>
>>>You can SELECT :-)
>>
>>You mean from the DB? Or how to use SELECT in the ASP.NET Grid View?
>
>No, from DataTable :-)
>Something like:
>
>DataRow[] drws = DataTable.Select(...);
>if(drws.Length==0)
>{
>// Found some rows
>}
>
>
>I'm sure that there is LINQ way to do this.

DataTable.Select (https://msdn.microsoft.com/en-us/library/det4aw50%28v=vs.110%29.aspx) uses the awful DataColumn Expression commands and doesn't have any compile time checking or refactoring support. To do it in LINQ, just need to use AsEnumerable (https://msdn.microsoft.com/en-us/library/system.data.datatableextensions.asenumerable%28v=vs.110%29.aspx)
var matchingRows = DataTable.AsEnumerable().Where(dr => dr.Field< string>("CustName") == searchText);

var matchingOrderNumbers = matchingRows.Select(dr => dr.Field< string>("OrderNum"));
var firstMatchingOrderNum = matchingOrderNumbers.FirstOrDefault();
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform