Reputation: 419
I was using Gridview for a while now and I have noticed that its very easy to create a simple table and populate it with date f.e.
ID Name Surename Phone .....
1 Tom Tomtom 111122233
2 Vic VicVic 21231231
3 Rik RikRik 123545343
So here we have a simple gridview with three records, every record is in one line! What I need is to put one record info in three lines like here:
ID Name Surename Phone .....
/ 1 Tom Tomtom 111122233
record1 { Additional info: blablabla
\ More info: xxxxx
/ 2 Vic VicVic 21231231
record2 { Additional info: blablabla
\ More info: xxxxx
/ 3 Rik RikRik 123545343
record3 { Additional info: blablabla
\ More info: xxxxx
So here we have a Gridview and here we show One record's info in three lines...So how to do this?
I was using this code to populate my gridview when I have an Object of data but this works only with a single lines of records
private void grdMyGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
MyObject ObjectEl = (MyObject)e.Row.DataItem;
e.Row.Cells[0].Text = ObjectEl.ID.ToString();
e.Row.Cells[1].Text = ObjectEl.Name.ToString();
e.Row.Cells[2].Text = ObjectEl.Surename.ToString();
LinkButton lbtConfigure = (LinkButton)e.Row.Cells[3].FindControl("lbtConfigure");
lbtConfigure.CommandArgument = Convert.ToString(ObjectEl.ID);
}
}
Upvotes: 0
Views: 1023
Reputation: 5670
you can use templating for this purpose. insert tables inside header template and item template(according to your need). inside tables you can insert labels. bind labels with the columns in your datatable.(Eval("columnname")). now you got the gridview as you expected.
Upvotes: 0
Reputation: 406
Templating rows like this is possible in a gridview, but the listview control is much better suited to this type of data.
Take a look here, this will get you started.
Upvotes: 1