.net8 blazor grid not showing data rows!

1 Answer 10 Views
Grid
Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
Deasun asked on 27 Mar 2024, 04:52 PM

I have a basic .net8 project , the VS template one, I following the instructions to hook up telerik to it.

The btn works.

I then added a grid, which shows up, but I see no records in it. I dont see what I am doing wrong.

razor page:

@page "/GridTester"
<h3>GridTesting</h3>

<h1>@strTaskDone</h1>

<TelerikLoaderContainer Visible="@ldrVisible" Class="no-panel">
    <Template>
        <TelerikLoader></TelerikLoader>
        <div>
            <span></span>
            <span>Please wait, I am currenlty working on it...</span>
        </div>
    </Template>
</TelerikLoaderContainer>


<TelerikGridLayout>
    <GridLayoutColumns>
        <GridLayoutColumn Width="100%"></GridLayoutColumn>    
    </GridLayoutColumns>
    <GridLayoutRows>   
        <GridLayoutRow Height="@strAppMsgHT"></GridLayoutRow>               @*App Msg*@   
        <GridLayoutRow Height="@strGridHT"></GridLayoutRow>                 @*Report Grids *@
    </GridLayoutRows>
     <GridLayoutItems>
        <GridLayoutItem Row="1" Column="1" >
            <TelerikButton OnClick="@SayHelloHandler"
                           ThemeColor="@ThemeConstants.Button.ThemeColor.Primary">Say Hello</TelerikButton>
        </GridLayoutItem>
         <GridLayoutItem Row="2" Column="1" ColumnSpan="2">
            <TelerikGrid @ref="@gridOrderListDetails"
                         Data="@grdOrderListDetails"
                         AutoGenerateColumns="true"
                         Width="800px"
                         Pageable="true"
                         Sortable="true"
                         FilterMode="@GridFilterMode.FilterRow">
            </TelerikGrid>
        </GridLayoutItem>
    </GridLayoutItems>
</TelerikGridLayout>

code behind stuff for the Grid:

 public TelerikGrid<rtpOrderListDetailsResults> gridOrderListDetails { get; set; }  // grid on the webpage
 private List<rtpOrderListDetailsResults> grdOrderListDetails { get; set; }

 DataTable dt = new DataTable();
 SqlConnection con = new SqlConnection(strConn);
 SqlDataAdapter da = new SqlDataAdapter(strCMDToRun, con);
 da.SelectCommand.CommandTimeout = 540000;
 da.Fill(dt);
 foreach (DataRow row in dt.Rows)
 {
     if (dt.Columns.Count == 1)
     {
         ResultRow = new rtpOrderListDetailsResults();
         ResultRow.PON = row["Result"] as string;
     }
     else
     {
         ResultRow = new rtpOrderListDetailsResults();
         ResultRow.PON = row["PON"] as string;
         ResultRow.Customer_ID = (Int64)row["Customer_ID"];
         ResultRow.Customer_Name_Billing = row["Customer_Name_Billing"] as string;
         ResultRow.Parent_Name = row["Parent_Name"] as string;
         ResultRow.TN = row["TN"] as string;
         ResultRow.Nbr_Of_Actual_Lines = (Int32)row["Nbr_Of_Actual_Lines"];

         if (row["CreatedDT"] != DBNull.Value)
         {
             d = DateOnly.FromDateTime((DateTime)row["CreatedDT"]);
             ResultRow.CreatedDT = d;
         };

         if (row["DueDT"] != DBNull.Value)
         {
             d = DateOnly.FromDateTime((DateTime)row["DueDT"]);
             ResultRow.DueDT = d;
         };

         ResultRow.Current_Status = row["Current_Status"] as string;

         if (row["Current_StatusDT"] != DBNull.Value)
         {
             d = DateOnly.FromDateTime((DateTime)row["Current_StatusDT"]);
             ResultRow.Current_StatusDT = d;
         };
         // ResultRow.Current_StatusDT = row["Current_StatusDT"] as DateTime?;

         ResultRow.Provisioner_Assigned = row["Provisioner_Assigned"] as string;
         ResultRow.Agent_Is = row["Agent_Is"] as string;
         ResultRow.Carrier = row["Carrier"] as string;
         ResultRow.Carrier_ID = (Int32)row["Carrier_ID"];
         ResultRow.Provisioning_Process = row["Provisioning_Process"] as string;
         ResultRow.Class = row["Class"] as string;
         ResultRow.Provisioning_Age_Days = (Int32)row["Provisioning_Age_Days"];
         ResultRow.Order_Type = row["Order_Type"] as string;
         ResultRow.Line_Type = row["Line_Type"] as string;
         ResultRow.Line_Description = row["Line_Description"] as string;
         ResultRow.State = row["State"] as string;
         ResultRow.Open_Related_Orders = row["Open_Related_Orders"] as string;
         ResultRow.Channel = row["Channel"] as string;
         ResultRow.Bill_Profile = row["Bill_Profile"] as string;

         ResultRow.MRC_ChargesAmt = (decimal)row["MRC_ChargesAmt"];
         ResultRow.MRC_Line_ChargesAmt = (decimal)row["MRC_Line_ChargesAmt"];

         ResultRow.Cancel_Reason = row["Cancel_Reason"] as string;
         ResultRow.Hold_Reason = row["Hold_Reason"] as string;
         ResultRow.Prime = row["Prime"] as string;
         ResultRow.Cycle_Is = (Int32)row["Cycle_Is"];
         // ResultRow.Impacted_By_COVID19 = row["Impacted_By_COVID19"] as string;
         ResultRow.Term_Nber_Of_Months = (Int32)row["Term_Nber_Of_Months"];
         ResultRow.Upload = row["Upload"] as string;
         ResultRow.Download = row["Download"] as string;
         ResultRow.AMProjectManager = row["AMProjectManager"] as string;

         RptResults.Add(ResultRow);
     };


 };

 grdOrderListDetails = RptResults;

 if (gridOrderListDetails.Data.Count() > 0)
 {
     gridOrderListDetails.AutoFitAllColumns();
 };

 if (grdOrderListDetails.Count > 0)
 {
     strTaskDone = "Completed";
 }
 else
 {
     strTaskDone = "Me Sad";
 };

This has data: grdOrderListDetails.Count

But this is NULL: gridOrderListDetails.Data

Why? 

 

1 Answer, 1 is accepted

Sort by
0
Nadezhda Tacheva
Telerik team
answered on 01 Apr 2024, 10:13 AM

Hi Deasun,

The Grid is currently bound to grdOrderListDetails which means it will try to extract the information from that collection. I see you are passing the RptResults to the grdOrderListDetails and it looks like this collection contains the rows from your DataTable.

For the AutoGenerateColumns feature, when initializing the Grid expects to know what columns to render before the data comes. When it does not have actual strongly typed models and uses dynamic objects, it cannot know what columns to render. Thus, this feature is not applicable in this case.

Try explicitly listing the column instances as shown here: https://demos.telerik.com/blazor-ui/grid/data-table.

In case this does not solve the problem, please send a runnable reproduction that I can debug and share more insights.

Regards,
Nadezhda Tacheva
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Tags
Grid
Asked by
Deasun
Top achievements
Rank 3
Bronze
Bronze
Bronze
Answers by
Nadezhda Tacheva
Telerik team
Share this question
or