启用文本框时,GridView中出现问题

时间:2018-12-31 13:36:25

标签: c# asp.net webforms

当我在图像中的一个过滤字符串之后更改数据源时,在检测文本框的启用状态时遇到问题->(https://imgur.com/a/JxTQ8ks

没有过滤器,我可以启用文本框添加值,添加股票成功(此tb用于添加股票) 在下面,即使启用了文本框,我的代码也会在此处失败( if(tb.Enabled)

    protected void ProductStock_Click(object sender, EventArgs e)
    {
        int productID = Convert.ToInt32((sender as LinkButton).CommandArgument); /*Pega o id do button que foi clicado*/

        Product product = ProductBLL.GetProductByID(productID);
        //cast the sender back to a button
        LinkButton cb = sender as LinkButton;

        //get the current gridviewrow from the button namingcontainer
        GridViewRow row = cb.NamingContainer as GridViewRow;

        //use findcontrol to locate the textbox in that row
        TextBox tb = row.FindControl("tbStockEntry") as TextBox;

        if (tb.Enabled)
        {
            if (tb.Text.Length > 0)
            {

                StockEntry se = new StockEntry();
                se.Product = product;
                se.StockEntryQuantity = Convert.ToInt32(tb.Text);

                if (ProductBLL.StockEntryInsert(se) == 1)
                {
                    cb.Text = GlobalMessages.Saving;
                    stockAddedLabel.Visible = true;
                    stockAddedLabel.Text = GlobalMessages.InsertedStock;
                    Response.AddHeader("REFRESH", "1;URL=ProductList.aspx");
                }
            }
            else
            {
                tb.Enabled = false;
                cb.Text = GlobalMessages.StockEntry;
            }

        }
        else
        {
            tb.Enabled = true;
            cb.Text = GlobalMessages.Save;
        }
    }

1 个答案:

答案 0 :(得分:0)

我已经解决了。问题是我没有使用事件单击进行过滤,而是调用了在页面加载中进行过滤的方法。它可以过滤,但是我无法为该产品添加库存。还是谢谢你!