views:

33

answers:

2

current output

alt text

wanted output

alt text

current code

public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            populateData();
    }

    private void populateData()
    {
        List<temp> ls = new List<temp>();

        ls.Add(new temp { a = "AAA", b = "aa", c = "a", dt = DateTime.Now });
        ls.Add(new temp { a = "BBB", b = "bb", c = "b", dt = DateTime.Now });
        ls.Add(new temp { a = "CCC", b = "cc", c = "c", dt = DateTime.Now.AddDays(1) });
        ls.Add(new temp { a = "DDD", b = "dd", c = "d", dt = DateTime.Now.AddDays(1) });
        ls.Add(new temp { a = "EEE", b = "ee", c = "e", dt = DateTime.Now.AddDays(2) });
        ls.Add(new temp { a = "FFF", b = "ff", c = "f", dt = DateTime.Now.AddDays(2) });


        TemplateField tc = (TemplateField)gv.Columns[0];  // <-- want to assign here just day
        gv.Columns.Add(tc); // <-- want to assign here just day + 1
        gv.Columns.Add(tc); // <-- want to assign here just day + 2

        gv.DataSource = ls; 
        gv.DataBind(); 
    }
}

public class temp
{
    public temp() { }

    public string a { get; set; }
    public string b { get; set; }
    public string c { get; set; }
    public DateTime dt { get; set; }
}

and in HTML

<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("a") %>' Font-Bold="true" /><br />
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("b") %>' Font-Italic="true" /><br />
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("dt") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

What I'm trying to avoid is repeat code so I can only use one unique TemplateField

I can accomplish this with 3 x GridView, one per each day, but I'm really trying to simplify code as the Grid will be exactly the same (as the HTML code goes), just the DataSource changes.

Any help is greatly appreciated, Thank you.

A: 

use ListView for this.

this. __curious_geek
`ListView` is the same as `GridView`, they both bind data per Row... I want per Row and per Column (each day per Column, and content of the day per Row in that Column)
balexandre
A: 

Hey,

You could create a custom template and supply that template three times, as in : http://msdn.microsoft.com/en-us/library/aa289501%28VS.71%29.aspx

Brian