On Oct 29, 2:20*pm, Ralf <marty.overd... @intergraph.com wrote:
I have a custome request to print a gridview with lots of columns, 31
to be exact. *I know how to print out a gridview, done it already for
a GV with 6 columns. *But, this GV is very wide and will not fit on a
page. *I looked into using a repeater, but couldn't figure it out.
Tried datalists, no luck.
Does anybody have an idea of how I can output the data where it will
print. *It doesn't have to output into a gridview, I just need it
printable...
Ralf, using Repeater with a nested GridView is quite easy. Here's an
example I used to show list of brochures by categories. The result
list looks in the following way:
Category1
.....col1....co l2....col3
.....col1....co l2....col3
.....col1....co l2....col3
Category 2
.....col1....co l2....col3
.....col1....co l2....col3
.....col1....co l2....col3
This is done by using Repeater with a nested GridView:
<asp:Repeater ID="Repeater1" runat="server"
OnItemDataBound ="Repeater1_Ite mDataBound">
<ItemTemplate >
<div>
<asp:Label ID="lblCategory Name" runat="server" Text='<%#
Eval("BrochureC ategoryName") %>' />
</div>
<div>
<asp:GridView ID="GridView1" runat="server" DataKeyNames="B rochureId">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
....
</ItemTemplate>
</asp:TemplateFie ld>
</Columns>
</asp:GridView>
</div>
</ItemTemplate>
</asp:Repeater>
A code to populate GridView could be as a following
private void BindData()
{
DataSet ds = (DataSet)db.Exe cuteDataSet(str ing.Format(
@"SELECT * FROM BrochureCategor y;
SELECT b.* FROM Brochure b, BrochureCategor y c
WHERE b.BrochureCateg oryId=c.Brochur eCategoryId", _websiteId)
);
// Attach the relationship to the dataSet
ds.Relations.Ad d(new DataRelation("C ategoriesRelati on",
ds.Tables[0].Columns["BrochureCatego ryId"],
ds.Tables[1].Columns["BrochureCatego ryId"]));
Repeater1.DataS ource = ds.Tables[0];
Repeater1.DataB ind();
}
protected void Repeater1_ItemD ataBound(object sender,
RepeaterItemEve ntArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
DataRowView drv = e.Item.DataItem as DataRowView;
GridView GridView1 = e.Item.FindCont rol("GridView1" ) as GridView;
GridView1.DataS ource = drv.CreateChild View("Categorie sRelation");
GridView1.DataB ind();
}
}
When you have many colums you have to find how you could rearrange the
view. Maybe you can follow my example and show one or more "main"
columns as a Repeater data rows and the rest could be nested using a
GridView control.
Category1 Name1 Name2
Description.... ..
.....col1....co l2....col3
.....col1....co l2....col3
.....col1....co l2....col3
or
Category1 Name1 Name2
Description.... ..
.....col1=val1
.....col2=val2
.....col3=val3
.....col4=val4
.....col5=val5