Printing Gridview with LOTS of columns

Discussion in 'ASP .Net' started by Ralf, Oct 29, 2008.

  1. Ralf

    Ralf Guest

    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, Oct 29, 2008
    #1
    1. Advertising

  2. On Oct 29, 2:20 pm, Ralf <> 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....col2....col3
    .....col1....col2....col3
    .....col1....col2....col3
    Category 2
    .....col1....col2....col3
    .....col1....col2....col3
    .....col1....col2....col3

    This is done by using Repeater with a nested GridView:

    <asp:Repeater ID="Repeater1" runat="server"
    OnItemDataBound="Repeater1_ItemDataBound">
    <ItemTemplate>
    <div>
    <asp:Label ID="lblCategoryName" runat="server" Text='<%#
    Eval("BrochureCategoryName") %>' />
    </div>
    <div>

    <asp:GridView ID="GridView1" runat="server" DataKeyNames="BrochureId">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>

    ....

    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

    </div>
    </ItemTemplate>
    </asp:Repeater>

    A code to populate GridView could be as a following

    private void BindData()
    {

    DataSet ds = (DataSet)db.ExecuteDataSet(string.Format(
    @"SELECT * FROM BrochureCategory;
    SELECT b.* FROM Brochure b, BrochureCategory c
    WHERE b.BrochureCategoryId=c.BrochureCategoryId", _websiteId)
    );

    // Attach the relationship to the dataSet
    ds.Relations.Add(new DataRelation("CategoriesRelation",
    ds.Tables[0].Columns["BrochureCategoryId"],
    ds.Tables[1].Columns["BrochureCategoryId"]));

    Repeater1.DataSource = ds.Tables[0];
    Repeater1.DataBind();

    }

    protected void Repeater1_ItemDataBound(object sender,
    RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    DataRowView drv = e.Item.DataItem as DataRowView;

    GridView GridView1 = e.Item.FindControl("GridView1") as GridView;
    GridView1.DataSource = drv.CreateChildView("CategoriesRelation");
    GridView1.DataBind();
    }
    }

    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....col2....col3
    .....col1....col2....col3
    .....col1....col2....col3

    or

    Category1 Name1 Name2
    Description......
    .....col1=val1
    .....col2=val2
    .....col3=val3
    .....col4=val4
    .....col5=val5
     
    Alexey Smirnov, Oct 29, 2008
    #2
    1. Advertising

  3. Ralf

    Ralf Guest


    >
    > Category1 Name1 Name2
    > Description......
    > ....col1=val1
    > ....col2=val2
    > ....col3=val3
    > ....col4=val4
    > ....col5=val5


    This is a possiblity of doing it this way. I would list the row
    identifier in at the Top, and then have the col1=val like you have it
    to show all the data. It doesn't matter if it runs multiple pages for
    each row. I will give this a try, probably tomorrow and post my
    results. Thx
     
    Ralf, Oct 29, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacksm
    Replies:
    2
    Views:
    861
    Paul Chalekian
    Nov 21, 2006
  2. Andrew Sackville-West

    MySQLdb, lots of columns and newb-ness

    Andrew Sackville-West, Dec 20, 2006, in forum: Python
    Replies:
    5
    Views:
    318
    Andrew Sackville-West
    Dec 20, 2006
  3. brad
    Replies:
    9
    Views:
    385
    Bruno Desthuilliers
    Jun 19, 2008
  4. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    891
    Vinki
    Apr 25, 2007
  5. coolneo
    Replies:
    9
    Views:
    203
    coolneo
    Jan 30, 2007
Loading...

Share This Page