Results 1 to 8 of 8

Thread: Question about web page DevExpress and Blazor

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Question about web page DevExpress and Blazor

    First of all, I don't know if I'm in the right forum so feel free to move this if you are a moderator and secondly I have a very specific question because I code 95% of the time in windows desktop applications and I can't speak about what I'm doing "generally", I will explain in terms of my modules and what the overall goal is.

    Our desktop winforms application has a new form that I'm also developing to run on the web. It is just a grid of data, very simple. The complexity (and fun) is because it has dynamic columns. Employees here work on projects and the grid displays those projects and who is doing what. For example, we have project roles: Assigned PA (PA), Review Technical Lead (Tech Rev), System Technician (ST) etc. There are currently 18 roles. I don't want to have to code them all statically. Because next week we might decide there are two more roles. So I want to be able to do something like SELECT * FROM xtblProjectRoles, get all the roles that exist right now and build the grid with a column for each, and the employee who is fulfilling that role will have his empID in the row for the project. The problem I am having is with my class, ProjectListModel. It's code as below with names "colRole" and the control # in of that role in the database table. Is there some dynamic way I can define this class so I'm not locked into knowing how many possible roles there are? That is, how I can make it work when next week we have colRole18 and colRole19? Here is file ProjectListModel.cs.
    Code:
        {
           public string? ProjectName { get; set; }
            public string? ProjectStatus { get; set; }
            public string? ProjectLevelOfEffort { get; set; }
            public string? ProjectType { get; set; }
            public string? ProjectTeam { get; set; }
            public string? CTS { get; set; }
            public string? colRole1 { get; set; }
            public string? colRole2 { get; set; }
            public string? colRole3 { get; set; }
            public string? colRole4 { get; set; }
            public string? colRole6 { get; set; }
            public string? colRole7 { get; set; }
            public string? colRole8 { get; set; }
            public string? colRole9 { get; set; }
            public string? colRole12 { get; set; }
            public string? colRole13 { get; set; }
            public string? colRole14 { get; set; }
            public string? colRole15 { get; set; }
            public string? colRole16 { get; set; }
            public string? colRole17 { get; set; }
            public string? colRole18 { get; set; }
            public string? PrevailingWage { get; set; }
        }
    Here is Index.razor. I started to work on the dynamic columns but had an error until I defined them all in the class above.
    Name:  Project List on the web code.jpg
Views: 146
Size:  41.9 KB

    I hope this makes sense. If I'm not explaining it well and you care, please ask questions and I'll say more. I didn't want to get overly complicated to start. Thank you.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,525

    Re: Question about web page DevExpress and Blazor

    Possibly useful link:

    https://www.thecodingforums.com/thre...-array.498459/

    Google:
    asp .net string array variables
    asp .net string array list

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Question about web page DevExpress and Blazor

    Thank you for the reply. The issue isn't the string, it's the class. So I googled "c# dynamically define a class based on a sql query output at runtime". I was going to look into ExpandoObject.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,261

    Re: Question about web page DevExpress and Blazor

    Quote Originally Posted by MMock View Post
    Thank you for the reply. The issue isn't the string, it's the class. So I googled "c# dynamically define a class based on a sql query output at runtime". I was going to look into ExpandoObject.
    But that's what jdc was probably alluding to:
    Instead of each role being its own Property of the Class, use a "general" Property which is an Array/List (of your "roles")
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Question about web page DevExpress and Blazor

    OK, I will look into how to do that. Thanks.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  6. #6

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    My Mustang GT
    Posts
    4,562

    Re: Question about web page DevExpress and Blazor

    So can either of you say, since you both seem to understand one another!, how I would change this to use an array or list. I would like to start small and maybe get rid of all these properties except the first two, put them in a list in the class, and test that. Can you help me get started so I can test the concept? I feel like without the existence of the this the compiler is going to say no way, you're not doing that!
    Name:  ProjectListModel.jpg
Views: 114
Size:  121.0 KB
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Question about web page DevExpress and Blazor

    You're explaining that your data grows linearly, but you're trying to define it horizontally.

    Think of a class as a data table: each instance represents a row, and each property represents a column.

    If your roles are stored as rows in xtblProjectRoles, then it doesn't make sense to define them as properties on the class because you wind up arbitrarily limiting yourself. Instead, define the roles as a collection:
    Code:
    public class ProjectListModel
    {
        public string? ProjectStatus { get; set; }
        // etc...
        public List<string> Roles { get; set; } = []
    }
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,261

    Re: Question about web page DevExpress and Blazor

    Quote Originally Posted by dday9 View Post
    You're explaining that your data grows linearly, but you're trying to define it horizontally.

    Think of a class as a data table: each instance represents a row, and each property represents a column.
    To continue this line of thought:
    the Role-property as a List/Array/Collection is the "3rd" dimension.

    Note: If you create a new instance ("Row") of this class, you set your Properties ("Columns"), and in your "Role"-Property you only (!) enter the roles that are assigned to this particular "row".
    Not all possible roles that exist.

    Meaning:
    Project1 has 3 roles assigned, Project5 has 10 roles, and so on.
    It could basically be just a "foreign key" to the table "xtblProjectRoles"

    For displaying it would be a simple query involving a Pivot of xtblProjectRoles (Rows become columns) and a LEFT JOIN on the Project-Table
    Last edited by Zvoni; May 8th, 2026 at 01:18 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width