Using custom object to map to entity property

Contissi

Member
Joined
Apr 16, 2012
Messages
5
Programming Experience
Beginner
I am attempting to generate an HTML table where both column count and width can be customized. I am also wanting to be able to bind specific columns from a table to their corresponding columns...

Example Schema:
[Invoice].[Quantity]
[Invoice].[ItemName]
[Invoice].[TotalAmount]

Originally, I was trying to mess with passing in an object with two properties (both Dictionaries).

Something like this:

public class CustomObject {
public Dictionary<string, int> THTitle_Width { get; set; }
public Dictionary<string, string> InvoiceColumn_CorrespondingTHTitle { get; set; }
}

My thought wanting to achieve something like:

THTitle_Width.Add("My Quantity Header", 100);
InvoiceColumn_CorrespondingTHTitle.Add("Quantity", "My Quantity Header");

Idea being that data within the [Invoice].[Quantity] column would then be known to fall under the table column "My Quantity Header" which in turn has a width of 100 (px).

This would then output:

<tr><th style="width:100px;">My Quantity Header</th></tr>
<tr><td>1</td></tr>
<tr><td>15</td></tr>
<tr><td>3</td></tr>
etc...

Reason being, you could just pass in this custom object and everything beyond that is handled. Is this possible? Maybe not in this way, but in another?

Thank you for any help/ideas you are able to give!
 
Maybe a bit late, but here it is anyways :)

Your best bet is probably by using Generic Lists or arrays of a custom object. The custom object contains all the properties you talk about, and the list/array can output what you want.

class cobj {
private int width = 50; // could be a standard width
private string header = "This Is A Header";
private string subheader = "Subheader";

public int Width { get return width; set width = value; };
public string Header { get return header; set header = value; }
public string Subheader { get return subheader; set subheader = value; }
}

Output:

foreach (cobj c in cobjList)
{
string output = "";

output += "<tr><th style='width:" + c.Width + "px;'>" + c.Header + "</th></tr>";
output += "<tr><td>" + c.ThatThingIWanted + "</td></tr>";
...etc...

I wrote this on my ipad so i hope i made no mistakes, otherwise sorry! :)
 
Back
Top Bottom