c# - 如何更改行数据绑定(bind)事件中gridview的值

标签 c# asp.net gridview

我想在 gridview 中隐藏手机号码的最后 4 位数字并将最后 4 位数字显示为 **** 。我只得到标题值而不是项目模板值。如何获取移动值/项目值并对其进行编辑并分配到 GridView ?

protected void gvrequests_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        string Mobile = e.Row.Cells[3].Text;
        string securedPhone = Mobile .Remove(6);
        string MobileSecured= securedPhone + "****";
        e.Row.Cells[3].Text=MobileSecured
     }

最佳答案

您需要首先检查该行是否是 DataRow。

protected void gvrequests_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
          // your logic will go here
        }
   }

关于c# - 如何更改行数据绑定(bind)事件中gridview的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32344839/

相关文章:

c# - 关于异步任务

c# - 显示哪个分数与哪个标签相关的 ML.Net 错误

c# - 在gridview中显示数据

android - 设计带有动画的复杂 Android UI

c# - 基于具有几个小数位的 double 生成唯一的哈希码

php - yii2 gridview过滤日期

c# - 使用 Visual Studio 2010 - C# 将数据从 Excel 传输到 Word

c# - 可移植 C# 应用程序中的 Mongodb

python - 在 Python、ASP.NET 中读取和返回 jpg 文件?

asp.net - 为最大请求数/秒优化 IIS 和 ASP.net