简体   繁体   English

在asp.net中打印报告

[英]print report in asp.net

hello i have created a purchase report in which i have used the grid but in case when the no of rows are less ie in case of one or two rows i have to add deafult row without binding the datacolumns so that the grid looks better and also when i print report i dont want to show this print button and url of my window 你好,我创建了一个购买报告,在其中我使用了网格,但是如果行数较少,即在一两行的情况下,我必须添加默认行而不绑定数据列,以便网格看起来更好,并且当我打印报告时,我不想显示此打印按钮和窗口的网址 在此处输入图片说明

and i have to display some thing like this 我必须展示这样的东西

在此处输入图片说明

this is my aspx code 这是我的aspx代码

<table style="width:100%;">
        <tr>
          <td class="style1">
            <div class="cmpnylogo">
            <!--<img id="imglogo" runat="server"/>-->
                <table style="width:100%;">
                    <tr>
                        <td class="style69">
                            &nbsp;</td>
                                <td>
                                <div>

                                    <table style="width:100%;">
                                        <tr>
                                            <td class="style61">
                                    <asp:Label ID="Label20" runat="server" Text="Office"></asp:Label>
                                            </td>
                                            <td>
                                    <asp:Label ID="lbloffice" runat="server" Text="Label"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="style61">
                                    <asp:Label ID="Label21" runat="server" Text="Works"></asp:Label>
                                            </td>
                                            <td>
                                    <asp:Label ID="lblworks" runat="server" Text="Label"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="style61">
                                    <asp:Label ID="Label22" runat="server" Text="Phone"></asp:Label>
                                            </td>
                                            <td>
                                    <asp:Label ID="lblphone" runat="server" Text="Label"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="style61">
                                    <asp:Label ID="lblemail" runat="server" Text="Email"></asp:Label>
                                            </td>
                                            <td>
                                    <asp:Label ID="lblmail" runat="server" Text="Label"></asp:Label>
                                            </td>
                                        </tr>
                                    </table>

                                </div>
                                </td>
                            </tr>
                            <tr>
                                <td class="style58" colspan="2">
                                <hr />
                                </td>
                            </tr>
                        </table>
            </div>
          </td>

        </tr>
        <tr>
            <td align="center" class="style1">
                <div class="dvtitle">
                <div class="title">Purchase Order</div>

                </div>
             </td>
        </tr>
        <tr>
            <td align="center" class="style1">
                <table style="width:100%;border-left-style:none;border-right-style:none;" border="1px">
                    <tr>
                        <td class="style64" valign="top">
                            <table style="width:100%;">
                                <tr>
                                    <td class="style70">
                                        <div class="dvitems">
                                            Kind attn:-
                                        </div>
                                    </td>
                                    <td align="left">
                                  <asp:Label ID="lblattn" runat="server" Text="Label"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style70">
                                        &nbsp;</td>
                                    <td>
                                        &nbsp;</td>
                                </tr>
                                <tr>
                                    <td class="style70">
                                        &nbsp;</td>
                                    <td align="left">
                                        <asp:Label ID="lblpartyadd" runat="server" Text="Label"></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td class="style63" valign="top">
                            <table style="width:117%; height: 126px;">
                                <tr>
                                    <td class="style68">
                           <div class="dvpo">Consignee
                           </div>
                                        </td>
                                        <td align="left">
                           <asp:Label ID="lblconsignee" runat="server"> 
                           </asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="style68">
                                            <div>
                                                Name</div>
                                        </td>
                                        <td align="left">
                                        <asp:Label ID="lblconname" runat="server" Text="Label"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="style68">
                                            <div>
                                                Address</div>
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lblconadd" runat="server" Text="Label"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="style68">
                                            <div>
                                                City</div>
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lblconcity" runat="server" Text="Label"></asp:Label></td>
                                    </tr>
                                    <tr>
                                        <td class="style68">
                                            <div>
                                                TINNO.</div>
                                        </td>
                                        <td align="left">
                                        <asp:Label ID="lblcontinno" runat="server" Text="Label"></asp:Label></td>
                                    </tr>
                                    <tr>
                                        <td class="style68">
                                            <div>
                                                ECC NO</div>
                                        </td>
                                        <td align="left">
                                          <asp:Label ID="lblconeccno" runat="server" Text="Label"></asp:Label></td>
                                    </tr>
                                </table>
                            </td>
                        <td valign="top" align="left">

                            <table style="width:100%;">
                                <tr>
                                    <td class="style67">
                                        <div class="dvpo">
                                            PoNo:</div>
                                    </td>
                                    <td>
                                        <asp:Label ID="lblpono" runat="server" Text="Label"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="style67">
                                        &nbsp;</td>
                                    <td>
                                        &nbsp;</td>
                                </tr>
                                <tr>
                                    <td class="style67">
                                        <div class="dvpo">
                                            Date:</div>
                                    </td>
                                    <td>
                                        <asp:Label ID="lbldate" runat="server" Text="Label"></asp:Label>
                                    </td>
                                </tr>
                            </table>

                        </td>
                    </tr>
                    </table>
             </td>
        </tr>
        <tr>
           <td>
            <div class="dvright">

            </div>
           </td>
        </tr>
        <tr>
            <td class="style2">

                                    <div class="dvitems">Dear Sir/Mam,</div>
                                    </td>

        </tr>
        <tr>
            <td class="style2">

            <div class="dvinstruction">
 We are Pleased to order the under mentioned item kindly make the arrangements for the dispatch of same

             </div>
            </td>

        </tr>
        <tr>
            <td class="style2">



            </td>
        </tr>
        <tr>
            <td>
             <table>
                    <tr>
                    <td>
  <div style="width:100%; overflow:auto;min-height:500px;">                                             
  <asp:GridView ID="GridView1" runat="server" width:auto Height:auto AutoGenerateColumns="False" ShowFooter="True" style="min-width:700px"
  onrowdatabound="GridView1_RowDataBound">

                         <Columns>
                        <asp:BoundField DataField="itdsrno" HeaderText="Srno" />
                        <asp:BoundField DataField="itemname" HeaderText="Item" />
                        <asp:BoundField DataField="itdlength" HeaderText="Gsm" />
                        <asp:TemplateField HeaderText="Qty">
                        <FooterTemplate>
                        <asp:Label ID="lbltotalquan" runat="server" Text="Label"></asp:Label>
                         </FooterTemplate>
                         <ItemTemplate>
                            <asp:Label ID="lblquantity" runat="server" Text='<%# Eval("itdquan") 

%>'> %>'>

String.Format("{0:f2}",DataBinder.Eval(Container.DataItem,"itdRate")) %>' > String.Format(“ {0:f2}”,DataBinder.Eval(Container.DataItem,“ itdRate”))%>'>

                        <asp:TemplateField HeaderText="Amount">
                            <FooterTemplate>
                                <asp:Label ID="lbltxttotal" runat="server"  />
                            </FooterTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblamount" runat="server" Text='<%# 

String.Format("{0:f2}",DataBinder.Eval(Container.DataItem,"itdAmou")) %>' > String.Format(“ {0:f2}”,DataBinder.Eval(Container.DataItem,“ itdAmou”))%>'>

                        </asp:TemplateField>

                        <asp:BoundField DataField="itdrema" HeaderText="Remark" />
                    </Columns>

                </asp:GridView>
</div>


                        </td>
                    </tr>
                 </table>

            </td>
        </tr>
    </table>

and cs code is 和cs代码是

 if (!IsPostBack)
    {
        int compcode=0;
        c.GetConection();
        if(Session["compcode"]!=null)
        {
        compcode=Convert.ToInt32(Session["compcode"]);
        DataTable dtcomp = new DataTable();
        da = new SqlDataAdapter();
        SqlCommand cmdcom = new SqlCommand("sp_Getcompanyinfobycode",c.con);
        cmdcom.CommandType = CommandType.StoredProcedure;
        cmdcom.Connection = c.con;
        cmdcom.Parameters.AddWithValue("@compcode", compcode);
        da.SelectCommand = cmdcom;
        da.Fill(dtcomp);
        if (dtcomp.Rows.Count > 0)
        {
            if (dtcomp.Rows[0]["compadd1"] != null)
            {
                if (!string.IsNullOrEmpty(dtcomp.Rows[0]["compadd1"].ToString()))
                {

                    lbloffice.Text= dtcomp.Rows[0]["compadd1"].ToString();
                }
                else
                {
                    lbloffice.Text = "";
                }
                if (!string.IsNullOrEmpty(dtcomp.Rows[0]["compphor"].ToString()))
                {

                    lblphone.Text = dtcomp.Rows[0]["compphor"].ToString();
                }
                else
                {
                    lblphone.Text = "";
                }

            }
        }




        }



        System.Data.DataTable dt=new DataTable();
        da = new SqlDataAdapter("select convert(int,itdquan) as itdquan,convert(int,itdlength) as itdlength, * from tmpMateIn", c.con);
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {

            //if (dt.Rows.Count < 5)
            //{
            //    dt.Rows.Add(new object[] { "", "" });

            //}
            GridView1.DataSource = dt;

            GridView1.DataBind();



        }
        if (dt.Rows.Count > 0)
        {


            if (dt.Rows[0]["mstdate"] != null)
            {
                lbldeliverydt.Text = string.Format("{0:dd-MM-yyyy}", dt.Rows[0]["mstdate"]);
            }
            else
            {
                lbldeliverydt.Text = "";
            }
            if ((dt.Rows[0]["mstdeliDes"])!=null)
            {
                lblcity.Text = dt.Rows[0]["mstdeliDes"].ToString();
            }
            else
            {
                lblcity.Text = "";
            }
            if ((dt.Rows[0]["mstfrghtper"] != null))
            {
                if (!string.IsNullOrEmpty(dt.Rows[0]["mstfrghtper"].ToString()))
                {
                    decimal mstfrght = Convert.ToDecimal(dt.Rows[0]["mstfrghtper"].ToString());
                    lbldiscbill.Text = String.Format("{0:f2}", mstfrght);
                }
            }
            else
            {
                lbldiscbill.Text = "";
            }
            if ((dt.Rows[0]["msttaxper"] != null))
            {
                if (!string.IsNullOrEmpty(dt.Rows[0]["msttaxper"].ToString()))
                {
                    decimal msttaxper = Convert.ToDecimal(dt.Rows[0]["msttaxper"].ToString());

                    lbltax.Text = String.Format("{0:f2}", msttaxper);
                }
            }
            else
            {
                lbltax.Text = "";
            }
            if ((dt.Rows[0]["mstpayDes"] != null))
            {
                lblpterm.Text = dt.Rows[0]["mstpayDes"].ToString();
            }
            else
            {
                lblpterm.Text = "";
            }
            if ((dt.Rows[0]["itdrefq"] != null))
            {
                if (!string.IsNullOrEmpty(dt.Rows[0]["itdrefq"].ToString()))
                {
                    decimal itdrefq = Convert.ToDecimal(dt.Rows[0]["itdrefq"].ToString());
                    lblvattinno.Text = String.Format("{0:f2}", itdrefq);
                }
            }
            else
            {
                lblvattinno.Text = "";
            }

            da = new SqlDataAdapter();
            DataTable dtmtdetail = new DataTable();
            SqlCommand cmd = new SqlCommand("sp_Getordemstdetailbycode", c.con);
            cmd.Parameters.AddWithValue("@mstcode", dt.Rows[0]["mstcode"]);
            cmd.Parameters.AddWithValue("@compcode", dt.Rows[0]["compcode"]);
            cmd.Parameters.AddWithValue("@msttype", dt.Rows[0]["msttype"]);
            cmd.CommandType = CommandType.StoredProcedure;
            da.SelectCommand = cmd;
            da.Fill(dtmtdetail);
            if (dtmtdetail.Rows.Count > 0)
            {
                if ((dtmtdetail.Rows[0]["mstindno"] != null))
                {
                    if (!string.IsNullOrEmpty(dtmtdetail.Rows[0]["mstindno"].ToString()))
                    {
                        decimal mstindno = Convert.ToDecimal(dtmtdetail.Rows[0]["mstindno"].ToString());
                        lblcsttinno.Text = string.Format("{0:f2}", mstindno);
                    }
                }
                else
                {
                    lblcsttinno.Text = "";
                }
                if ((dtmtdetail.Rows[0]["mstsection"] != null))
                {
                    if (!string.IsNullOrEmpty(dtmtdetail.Rows[0]["mstsection"].ToString()))
                    {
                        lbleccno.Text = string.Format("{0:f2}", dtmtdetail.Rows[0]["mstsection"].ToString());
                    }
                }
                else
                {
                    lbleccno.Text = "";
                }





            }

            da = new SqlDataAdapter();
            DataTable dtpartyinfo = new DataTable();
            SqlCommand cmd1 = new SqlCommand("sp_GetAccountinfo", c.con);
            cmd1.Parameters.AddWithValue("@acctname", dt.Rows[0]["acctname"]);
            cmd1.CommandType = CommandType.StoredProcedure;
            da.SelectCommand = cmd1;
            da.Fill(dtpartyinfo);
            if (dtpartyinfo.Rows.Count > 0)
            {

                if (dt.Rows[0]["acctaddr"] != null)
                {
                    if (!string.IsNullOrEmpty(dtpartyinfo.Rows[0]["acctaddr"].ToString()))
                    {

                        lblpartyadd.Text = dtpartyinfo.Rows[0]["acctaddr"].ToString();
                    }
                    else
                    {
                        lblpartyadd.Text = "";
                    }
                }


            }






            lblpono.Text = dt.Rows[0]["compcode"].ToString();
            if (dt.Rows[0]["mstdate"] != null)
            {

                lbldate.Text = String.Format("{0:dd-MM-yyyy}", dt.Rows[0]["mstdate"]);
            }
            else
            {
                lbldate.Text = "";
            }
            lblconsignee.Text = dt.Rows[0]["mstdepa"].ToString();
            lblattn.Text = dt.Rows[0]["acctname"].ToString();
            if (dt.Rows[0]["acctname"] != null)
            {
                lblcompany.Text = "For " + dt.Rows[0]["acctname"].ToString();
            }
            imglogo.Attributes.Add("src", "/office%20pro/CrystalImageHandler.aspx?dynamicimage=cr_tmp_image_86d5effd-30fa-48d6-9a87-49b5ae9a616a.png");
            da = new SqlDataAdapter();
            DataTable dtconsigneeinfo = new DataTable();
            SqlCommand cmd2 = new SqlCommand("sp_GetAccountinfo", c.con);
            cmd2.Parameters.AddWithValue("@acctname", dt.Rows[0]["mstdepa"]);
            cmd2.CommandType = CommandType.StoredProcedure;
            da.SelectCommand = cmd2;
            da.Fill(dtconsigneeinfo);
            if (dtconsigneeinfo.Rows.Count > 0)
            {
                if (dtconsigneeinfo.Rows[0]["acctphon"] != null)
                {
                    if (!string.IsNullOrEmpty(dtconsigneeinfo.Rows[0]["acctphon"].ToString()))
                    {

                        lblphone.Text = dtconsigneeinfo.Rows[0]["acctphon"].ToString();
                    }
                    else
                    {
                        lblphone.Text = "";
                    }
                }
                if (dtconsigneeinfo.Rows[0]["acctaddr"] != null)
                {
                    if (!string.IsNullOrEmpty(dtconsigneeinfo.Rows[0]["acctaddr"].ToString()))
                    {

                        lbloffice.Text = dtconsigneeinfo.Rows[0]["acctaddr"].ToString();
                    }
                    else
                    {
                        lbloffice.Text = "";
                    }
                }


            }



        }

    }

If you want to so some thing when there is no row in your gridview then you can use EmptyDataTemplate of gridview. 如果您希望在gridview中没有任何行时进行某些操作,则可以使用gridview的EmptyDataTemplate。
When there is no data in the gridview this template is shown. 当gridview中没有数据时,将显示此模板。
Since it is a template so you can design it according to your choice. 由于它是模板,因此您可以根据自己的选择进行设计。
Here is an example of this . 下面是一个例子

There too is an example of stack overflow 也有一个堆栈溢出的例子


If you want to add something below you gridview you can use footer template. 如果要在gridview下面添加一些内容,则可以使用页脚模板。
There is a good example of footer template. 页脚模板是一个很好的例子。 http://www.ezzylearning.com/tutorial.aspx?tid=1676759 . http://www.ezzylearning.com/tutorial.aspx?tid=1676759
Since it is a template you can use html or server control inside it. 由于它是模板,因此可以在其中使用html或服务器控件。


<FooterTemplate>
   <asp:Label ID="lbltotalquan" runat="server" Text="Label"></asp:Label>
 <table>
     <tr>
         <td style='height:50px;'></td>
     <tr/>
 </table>
 </FooterTemplate>

This will create additional space below your footer. 这将在页脚下方创建额外的空间。 It can be done from code behind also. 也可以从后面的代码中完成。 Count the number of records in your datasouce and add table in footer. 计算数据源中的记录数,并在页脚中添加表。

I found the solution. 我找到了解决方案。 How I can miss it. 我怎么会想念它。 You can use style sheet for solving the problem. 您可以使用样式表解决问题。
use min-height property of CSS. 使用CSS的min-height属性。
here is a link 这是一个链接
http://www.w3schools.com/cssref/pr_dim_min-height.asp http://www.w3schools.com/cssref/pr_dim_min-height.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM