首页 > 解决方案 > 启用文本框时网格视图中的问题

问题描述

当我在图像中的过滤器字符串之后更改 DataSource 时,检测 TextBox 的启用状态时遇到问题->(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;
        }
    }

标签: c#asp.netwebforms

解决方案


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


推荐阅读