页面重新加载后GridView不可见

时间:2016-04-08 07:43:38

标签: asp.net gridview

我有一个小型网络应用程序只是为了节省一些结算价值...... 我有一个网格视图,我在其中添加值,然后单击提交将所有值保存到数据库。问题是在提交第一个值时显示gridview,在提交页面后重新加载到同一页面并生成新的发票号...当我输入值然后绑定gridview时,值由网格视图但未显示...网格视图不可见但它具有值...任何人都可以找到解决方案吗?

这是我的添加按钮

protected void btnadd_Click(object sender, EventArgs e)
    {
        if (txbfree.Text == "")
            txbfree.Text = "0";
        if (txbitm.Text==""|| ddtyp.SelectedIndex == 0)
            ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Please select the commodity and type !');", true);
        else
        {
            DataRow itm = dt1.NewRow();

            itm["schl.with_entry_no"] = txbschl.Text;
            itm["commodity"] = txbitm.Text;
            itm["type"] = ddtyp.Text;
            itm["rate_of_tax"] = txbtax.Text;
            itm["unit_price"] = txbuprice.Text;
            itm["quantity"] = txbqnty.Text;
            itm["gross_value"] = txbgv.Text;
            itm["cash_discount"] = txbcsh.Text;
            itm["MRP"] = lbmrp.Text;
            itm["taxable_amount"] = lbnttxamnt.Text;
            itm["tax_amount"] = lbtxamnt.Text;
            itm["total"] = lbtotal.Text;
            itm["free"] = txbfree.Text;
            itm["pr"] = ddpr.Text;
            dt1.Rows.Add(itm);

            grd8.DataSource = dt1;
            grd8.DataBind();
            txbschl.Text = "";
            txbitm.Text = "";
            txbtax.Text = "";
            txbuprice.Text = "";
            txbqnty.Text = "";
            txbgv.Text = "";
            txbcsh.Text = "";
            lbmrp.Text = "";
            lbnttxamnt.Text = "";
            lbtxamnt.Text = "";
            lbtotal.Text = "";
            ddtyp.SelectedIndex = 0;
            txbfree.Text = "";
            btntotal.Text = "Total?";
            lbwp.Text = "";
            chck.Checked = false;
            ddpr.SelectedIndex = 0;
            lbpf.Text = "0";

        }
    }

这是我的提交按钮

protected void btnsbmt_Click(object sender, EventArgs e)
    {

        try
        {
            int sl = 0;
            if (dt1.Rows.Count != 0)
            {
                if (txbdate.Text != "" && lbinvceno.Text != "" && txbdlrn.Text != "" && txbtin.Text != "")
                {
                    DateTime Test;
                    if (DateTime.TryParseExact(txbdate.Text, "dd/MM/yyyy", null, System.Globalization.DateTimeStyles.None, out Test) == false)
                        ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Please enter a valid date of the form dd/MM/yyyy!');", true);
                    else
                    {



                        for (int i = 0; i < dt1.Rows.Count; i++)
                        {
                            sl = i + 1;
                            string a = dt1.Rows[i][0].ToString();
                            string b = dt1.Rows[i][1].ToString();
                            string c = dt1.Rows[i][2].ToString();
                            double d1 = Convert.ToDouble(dt1.Rows[i][3].ToString());
                            double ef1 = Convert.ToDouble(dt1.Rows[i][4].ToString());
                            double g = Convert.ToDouble(dt1.Rows[i][5].ToString());
                            double h1 = Convert.ToDouble(dt1.Rows[i][6].ToString());
                            double ij1 = Convert.ToDouble(dt1.Rows[i][7].ToString());
                            double k1 = Convert.ToDouble(dt1.Rows[i][8].ToString());
                            double l1 = Convert.ToDouble(dt1.Rows[i][9].ToString());
                            double m1 = Convert.ToDouble(dt1.Rows[i][10].ToString());
                            string ty = dt1.Rows[i][11].ToString();
                            string o = dt1.Rows[i][12].ToString();

                            double d = Math.Truncate(d1 * 100) / 100;
                            double ef = Math.Truncate(ef1 * 100) / 100;
                            double h = Math.Truncate(h1 * 100) / 100;
                            double ij = Math.Truncate(ij1 * 100) / 100;
                            double k = Math.Truncate(k1 * 100) / 100;
                            double l = Math.Truncate(l1 * 100) / 100;
                            double m = Math.Truncate(m1 * 100) / 100;



                            string q = "insert into tbl_Form8 values('" + sl + "','" + a + "','" + b + "','" + c + "','" + d + "','" + ef + "','" + g + "','" + h + "','" + ij + "','" + k + "','" + l + "','" + m + "','" + ty + "','" + o + "','" + txbdate.Text + "','" + lbinvceno.Text + "')";
                            cmd = new SqlCommand(q, con);
                            cmd.ExecuteNonQuery();
                            ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Form submitted successfully !');", true);
                        }


                        double tl = dt1.AsEnumerable().Sum(row => row.Field<double>("total"));

                        string q1 = "insert into tbl_Customer8 values('" + txbtin.Text + "','" + txbcst.Text + "','" + txbdlrn.Text + "','" + txbdlra.Text + "','" + txbPhone.Text + "','" + tl + "')";
                        cmd = new SqlCommand(q1, con);
                        cmd.ExecuteNonQuery();


                        string q2 = "insert into tbl_Payment8 values('" + Convert.ToInt32(lbinvceno.Text) + "','" + txbdlrn.Text + "','" + tl + "','0','0','" + txbdate.Text + "')";
                        cmd = new SqlCommand(q2, con);
                        cmd.ExecuteNonQuery();


                        cstckupd();
                        double p = Convert.ToDouble(lbtpf.Text);
                        double p1 = Math.Truncate(p * 100) / 100;
                        string q3 = "insert into tbl_ProfitLoss8 values('" + lbinvceno.Text + "','" + txbdate.Text + "','" + p1 + "')";
                        cmd = new SqlCommand(q3, con);
                        cmd.ExecuteNonQuery();

                        string q4 = "insert into tbl_Dealer values('" + txbdlrn.Text + "','" + txbdlra.Text + "','" + txbPhone.Text + "','" + txbtin.Text + "','" + txbcst.Text + "')";
                        cmd = new SqlCommand(q4, con);
                        cmd.ExecuteNonQuery();

                        txbdate.Text = "";
                        txbcst.Text = "";
                        txbtin.Text = "";
                        txbdlrn.Text = "";
                        txbdlra.Text = "";
                        lbtpf.Text = "0";
                        lbpf.Text = "0";

                    }
                }
                else
                    ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Please provide the initial details !');", true);
            }

            else
                ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "alert('Please add the details first !');", true);
        }
        catch
        {
            Response.Redirect("Form8.aspx");
        }
    }

Gridview设计

<asp:GridView ID="grd8" runat="server" AutoGenerateColumns="False"  OnRowDeleting="grd8_RowDeleting" RowStyle-Wrap="true" Width="100%"
    ShowFooter="True">
    <Columns>
        <asp:TemplateField HeaderText="Sl No">
            <ItemTemplate>
                <%# ((GridViewRow)Container).RowIndex + 1%>
            </ItemTemplate>
                </asp:TemplateField>

        <asp:BoundField DataField="schl.with_entry_no" HeaderText="Schl with entry no" />
        <asp:BoundField DataField="commodity" HeaderText="Commodity" />
        <asp:BoundField DataField="type" HeaderText="Type" />
        <asp:BoundField DataField="MRP" HeaderText="MRP" />
        <asp:BoundField DataField="rate_of_tax" HeaderText="Tax" />
        <asp:BoundField DataField="unit_price" HeaderText="Unit price" />
        <asp:BoundField DataField="quantity" HeaderText="Quantity" />
        <asp:BoundField DataField="cash_discount" HeaderText="Cash discount" />
        <asp:BoundField DataField="taxable_amount" HeaderText="Taxable amount" />
        <asp:BoundField DataField="tax_amount" HeaderText="Tax amount" />
        <asp:BoundField DataField="total" HeaderText="Total" />
        <asp:BoundField DataField="gross_value" HeaderText="Gross value" Visible="false" />
         <asp:BoundField DataField="free" HeaderText="Free" />

       <asp:CommandField ShowDeleteButton="True" ButtonType="Button"  />         
    </Columns>
    <RowStyle Wrap="True" />
</asp:GridView>

0 个答案:

没有答案