locked
Print Gridview with headers RRS feed

  • Question

  • User1310055179 posted

    Hi,

    I really need your help with printing a <g class="gr_ gr_325 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="325" data-gr-id="325">gridview</g> that is inside an iframe.

    The <g class="gr_ gr_84 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="84" data-gr-id="84">gridview</g> has AllowPaging set to true, and I would like for each page to be printed in a new page with the report header.

    Default.aspx:

    <span class="report_right_toolbar showmenu" id="printSpan" >
                                <asp:ImageButton ID="print" runat="server"  Width="25px" CssClass="toolbarImage"
                                    ImageUrl="~/Images/Devices-printer-icon.png" OnClientClick = "return PrintPanel();" ToolTip="Print"/>
                            </span>
    <iframe id="QurRep" scrolling="auto" style="width:99%height:97%;" runat="server" ></iframe>
    

    The iframe src is TabularReport.aspx and I add it from code behind, with some parameters.

    TabularReport.aspx:

    <body id="pageBody" runat="server">
        <form id="tabular_report" runat="server">
        <div id="report_div">
            <asp:GridView ID="GridView1" runat="server"    
                OnSorting="GridView_Sorting" HeaderStyle-HorizontalAlign="Center" OnPageIndexChanging="PageIndexChanging"
                  OnRowCreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound" >
                <Columns>
                    <asp:TemplateField> 
                        <ItemTemplate>  
                             
                        </ItemTemplate> 
                    </asp:TemplateField>
                    
                    <asp:TemplateField> 
                        <ItemTemplate>  
                            <asp:CheckBox ID="CheckBox_Items" runat="server" />
                        </ItemTemplate> 
                    </asp:TemplateField>
                    
                </Columns> 
            </asp:GridView>
            <asp:HiddenField ID="HiddenField_TotalRec" runat="server" />
        </div>
        </form>
    </body>

    I bind the grid using the following function (from DB):

    run_Grid("GridView1""""");
    

    Thanks

     

    Thursday, January 31, 2019 9:10 AM

All replies

  • User-2054057000 posted

    You can do this by passing the page number to the url of the page that has gridview. So this makes sense because you can then get the page number from Request.QueryString and then you can bind the gridview based on the page number.

    In your ifame you give the src with the page of the gridview with the page number in querystring. See below:

    <iframe id="QurRep" src="TabularReport.aspx?pn=2" scrolling="auto" style="width:99%; height:97%;" runat="server" ></iframe>

    Notice the src property set as src="TabularReport.aspx?pn=2". I think this way you can do your work.

    Basically you are trying to acheive this:

    1. A GridView that is placed in some other page.
    2. Showing that some other page's gridview in another page. 
    3. This way you want to remove code duplication and reuse the gridview in multiple pages.

    There is another way to achive this by binding the other page's gridview using ajax and reuse it in multiple pages. I provide you a reference of this tutorial - Bind GridView with Paging using jQuery Load with No Page Refresh

    I hope it helps you.

    Thanks & Regards

    Thursday, January 31, 2019 10:02 AM
  • User1310055179 posted

    I need to print all pages in one click, that is actually my problem.

    The number of rows in a page needs to be as defined in the table pager.

    The table is inside the <g class="gr_ gr_11 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="11" data-gr-id="11">iframe</g>, but the print icon is located <g class="gr_ gr_13 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="13" data-gr-id="13">in</g> the page that contains the iframe.

    If the iframe only makes things complicated, I can first try and find a solution for printing all pages with one click, within the <g class="gr_ gr_12 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del" id="12" data-gr-id="12">iframe</g>.

    I need to see the header and page number in each page. 

    I found the following solution but I'm not sure how to use it with my code:

    https://www.codeproject.com/Articles/20903/Printing-a-GridView-with-Paging

    Monday, February 4, 2019 7:43 AM
  • User839733648 posted

    Hi qsoft_developer,

    According to your description, I'm confused about your requirement.

    An iframe is just a medium that shows the links you need.

    What you want to do in your page is decided by the thing you've done in the link.

    In my opinion, as long as you follow the link and could print the page, it will also work in the iframe.

    The function you've achieved in the TabularReport will not be affected by the iframe page.

    Best Regards.

    Jenifer

    Tuesday, February 12, 2019 6:44 AM