[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

LINQ will not databind to datagrid.  No rows will display when LINQ result has data.

Posted on 2009-04-22
6
Medium Priority
?
810 Views
Last Modified: 2013-11-15
I am trying to attach a LINQ result to a Infragistics UltraWebGrid.  When I display the grid on the web page, no data appears in the rows. I have put a test in the code to verify the data exist in the LINQ statement and it does.  But, when the grid is displayed, no rows of data appear.  I tried plucking a field of data from the Infragistics Web Grid and it returns a no data.  But....you can look at the result set from the LINQ statement and there is data in the result set.  I have used the very same code on another page and it works fine with a different table.  Any ideas would be greatly appreciated.
RadRelayDataClassDataContext dcRadRelay = new RadRelayDataClassDataContext();
 
            // Read  Table "Providers"
 
            var ProviderResult = from providerdata in dcRadRelay.PROVIDERs
                                 where providerdata.FIRST_NAME == tbDocFname.Text ||
                                 providerdata.LAST_NAME == tbDocLname.Text ||
                                 providerdata.CITY == tbDocCity.Text ||
                                 providerdata.STATE == tbDocState.Text ||
                                 providerdata.ZIP == tbDocZip.Text
 
                                 select new { providerdata };
 
            int providerRecCount = ProviderResult.Count();    // <===== Added this line to get total count here
 
            if (providerRecCount == 0)                    // <===== Changed this line so that the query does not get executed again
            {
                // No user record found
            }
            else
            {
                foreach (var providerResultRecord in ProviderResult)
                {
                    // Set the grid to the data source
                    this.UltraWebGrid2.DataSource = ProviderResult;-----<<<----ProviderResult shows one record
 
                    //this.UltraWebGrid2.DisplayLayout.AutoGenerateColumns = false;
                    //UltraWebGrid2.DisplayLayout.Bands.Clear();
 
                    this.UltraWebGrid2.DataBind();
 
 
                    string test;----<<<<-----Here is the test that shows no data available
                    test = this.UltraWebGrid2.DisplayLayout.SelectedRows[0].Cells.FromKey("LAST_NAME").Text;
 
                    UltraGridColumn lnCol = new UltraGridColumn();
                    lnCol.BaseColumnName = "LAST_NAME";
                    lnCol.Key = "LAST_NAME";
                    this.UltraWebGrid2.DisplayLayout.Bands[0].Columns.Add(lnCol);
 
                    UltraGridColumn fnCol = new UltraGridColumn();
                    fnCol.BaseColumnName = "FIRST_NAME";
                    fnCol.Key = "FIRST_NAME";
                    this.UltraWebGrid2.DisplayLayout.Bands[0].Columns.Add(fnCol);

Open in new window

0
Comment
Question by:kwh3856
  • 3
  • 2
6 Comments
 
LVL 10

Accepted Solution

by:
GeoffSutton earned 1000 total points
ID: 24213639
Does the ultrawebgrid support Linq?  If you replace it with a simple asp:gridview do you get the results you wanted?  If so, you have have to manually convert the Linq results to a datatable.
Geoff
0
 
LVL 9

Assisted Solution

by:Sreedhar Vengala
Sreedhar Vengala earned 1000 total points
ID: 24220559
just a try :
change your query to
(from providerdata in dcRadRelay.PROVIDERs
                                 where providerdata.FIRST_NAME == tbDocFname.Text ||
                                 providerdata.LAST_NAME == tbDocLname.Text ||
                                 providerdata.CITY == tbDocCity.Text ||
                                 providerdata.STATE == tbDocState.Text ||
                                 providerdata.ZIP == tbDocZip.Text).ToList();
also look at : http://news.infragistics.com/forums/t/6430.aspx
 
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24220593
Is Query result of anonymous types. If so should be the case.
Dealing with Anonymous Types in Linq see http://weblogs.asp.net/scottgu/archive/2007/05/15/new-orcas-language-feature-anonymous-types.aspx?CommentPosted=true 
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:kwh3856
ID: 24220681
sree and Geoff,
I got it figured out.  Here was the answer to my problem.  I had to specify each of the fields of data that I wanted to used in the grid.  

 var ProviderResult = from providerdata in dcRadRelay.PROVIDERs
                                     where providerdata.FIRST_NAME == tbDocFname.Text ||
                                     providerdata.LAST_NAME == tbDocLname.Text ||
                                     providerdata.CITY == tbDocCity.Text ||
                                     providerdata.STATE == tbDocState.Text ||
                                     providerdata.ZIP == tbDocZip.Text
 
                                     select new { providerdata.LAST_NAME, providerdata.FIRST_NAME, providerdata.ADDRESS_1,
                                         providerdata.CITY, providerdata.STATE, providerdata.PHONE, providerdata.PHYSICIAN_NPI};---<<<--The Solution

Open in new window

0
 

Author Closing Comment

by:kwh3856
ID: 31573649
Thank you both for trying to help.
0
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24220685
Cool
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question