c# - 启用文本框时网格视图中的问题
问题描述
当我在图像中的过滤器字符串之后更改 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;
}
}
解决方案
我已经解决了。问题是我没有使用事件点击进行过滤,而是调用了页面加载中的过滤方法。它可以过滤,但我无法为产品添加库存。不管怎么说,还是要谢谢你!
推荐阅读
- php - 将一组重写规则从php导出到apache:这可能吗?
- php - 如何从 5.6 更新 Google Compute Engine 中的 PHP?
- python - RuntimeWarning:从未等待协程。如何异步/等待回调
- hyperledger-fabric - fabric-ca-server 隶属关系命令行选项
- c# - 将自定义控件序列化为 JSON 文件
- php - 如果帖子数据不符合参数,如何排除某些帖子显示在 wp_query 中?
- c# - 通过 SDK 调用方法调用方法不会返回预期的输出
- nativescript - 在 iOS 上测试 nativescript 构建
- automated-tests - jldoctest 包含在文档中的 julia 文档字符串中的块,但未在其上运行测试
- excel - 每周生成的报告中的 VBA 复制粘贴