简体   繁体   中英

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

<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")) %>' >

                        <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")) %>' >

                        </asp:TemplateField>

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

                </asp:GridView>
</div>


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

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

and cs code is

 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.
When there is no data in the gridview this template is shown.
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.
There is a good example of footer template. http://www.ezzylearning.com/tutorial.aspx?tid=1676759 .
Since it is a template you can use html or server control inside it.


<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.
here is a link
http://www.w3schools.com/cssref/pr_dim_min-height.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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