1

您好,我创建了一个购买报告,其中我使用了网格,但是如果行数较少,即一两行的情况下,我必须添加默认行而不绑定数据列,以便网格看起来更好,并且当我打印报告时,我不想显示此打印按钮和窗口的 url在此处输入图像描述

我必须展示这样的东西

在此处输入图像描述

这是我的 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")) %>' >

                        <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>

而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 = "";
                    }
                }


            }



        }

    }
4

2 回答 2

0

如果你想在你的gridview中没有行的时候做一些事情,那么你可以使用gridview的EmptyDataTemplate。
当 gridview 中没有数据时,会显示此模板。
由于它是一个模板,因此您可以根据自己的选择进行设计。
这是一个例子

还有一个堆栈溢出


的例子 如果你想在你的gridview下面添加一些东西,你可以使用页脚模板。
有一个很好的页脚模板示例。http://www.ezzylearning.com/tutorial.aspx?tid=1676759
由于它是一个模板,因此您可以在其中使用 html 或服务器控件。


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

这将在您的页脚下方创建额外的空间。它也可以从后面的代码中完成。计算数据源中的记录数并在页脚中添加表格。

于 2012-11-02T09:33:02.133 回答
0

我找到了解决方案。我怎么能错过它。您可以使用样式表来解决问题。
使用CSS 的min-height 属性。
这是一个链接
http://www.w3schools.com/cssref/pr_dim_min-height.asp

于 2012-11-08T07:26:18.067 回答