asp.net - 如何清除网格视图、文字和面板值?
问题描述
我有一个名为 customer id 的文本框,如果 id 无效,它应该显示一条警告消息,并且需要返回到用户再次尝试输入 Id 的主页。如果 ID 有效,它可以正常工作。如果输入的 Id 无效,则面板和网格视图将使用一些随机值进行更新。我怎样才能清除它们?有什么建议么。
DataTable dt = oRecord.GetCustomerName(sId);
if (dt.Rows.Count == 0)
{
// making panel and gridview visible false does not work.
pnlDetails.visible = false;
gvInfo.visible= false
pnlSuccess.Visible = false;
btnOk.Visible = false;
txtId.Text = string.Empty;
txtIdentifier.Focus();
ViewState["sId"] = string.Empty;
}
解决方案
您不应设置 visible false ,因为它将与现有数据一起将控件设置为不可见,但数据可用并与内存中的这些控件绑定。您应该将这些控件的内容清除为空或 null。
DataTable dt = oRecord.GetCustomerName(sId);
if (dt.Rows.Count == 0)
{
gvInfo.DataSource = null;
txtId.Text = string.Empty;
txtIdentifier.Focus();
ViewState["sId"] = string.Empty;
}
推荐阅读
- reactjs - 在 MUI 中更改 TextField 字体颜色?
- vb.net - 1 行 Datagridview 上的 ArgumentOutOfRangeException
- unix - 在 Unix 中更改文件名中已有数字的多个文件名
- http - 浏览器渲染的最小块大小
- php - php 致命错误:未捕获的错误:找不到类“路由器”
- docker - docker run“--cpus”标志令人困惑
- java - android中的AES加密和nodejs中的解密
- javascript - 如何将 Webpack 构建哈希注入应用程序代码
- android - 调用 activity.onSaveInstanceState() 后的 commit() 片段事务
- linux - 删除正在进行 I/O 的文件:它是文件系统和/或操作系统功能吗?