Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何更改行数据绑定事件中gridview的值_C#_Asp.net_Gridview - Fatal编程技术网

C# 如何更改行数据绑定事件中gridview的值

C# 如何更改行数据绑定事件中gridview的值,c#,asp.net,gridview,C#,Asp.net,Gridview,我想在gridview中隐藏手机号码的最后4位,并将最后4位显示为****。我只获取标题值,而不获取项目模板值。如何获取移动值/项目值并对其进行编辑和分配到网格视图 protected void gvrequests_RowDataBound(object sender, GridViewRowEventArgs e) { string Mobile = e.Row.Cells[3].Text; string securedPhone = Mobile .

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

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
        }
   }

rowdatabound
即使在每一行上激发,也意味着页眉行、数据行(也是备用行)和页脚行

因此,当您想要操作数据时,正如@Sain所建议的,您需要检查它是否是datarow,然后我们的逻辑实现


同样的逻辑也适用于页眉和页脚,但理想情况下,我们应该只用于数据行。

请添加您的标记代码。
protected void gvrequests_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        foreach (TableCell tc in e.Row.Cells)
        {

            tc.Attributes["style"] = "border-color: #87CEFA";

        }

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string Mobile = e.Row.Cells[3].Text;

            string securedPhone = Mobile .Remove(6);
           string MobileSecured= securedPhone + "****";
            e.Row.Cells[3].Text = MobileSecured;
        }
    }