user4525853
user4525853

Reputation:

how to change the value of a gridview in row data bound event

i want to hide last 4 digits of mobile number in gridview and show last 4 digits as **** . im getting only header value not item template values. how to get mobile values/item values and edit it and assign to grid view?

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
     }

Upvotes: 2

Views: 8381

Answers (3)

user4525853
user4525853

Reputation:

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

Upvotes: 2

Ajay2707
Ajay2707

Reputation: 5798

RowDatabBound even fired on each row means for header row , data row (alternate row too) and footer row.

So, when you want to manipulate the data, as @Sain suggest, you check that it is datarow then our logic implement.

The same logic is also apply for header and footer, but ideally we should use for the data row only.

Upvotes: 0

Sain Pradeep
Sain Pradeep

Reputation: 3125

You need to check the row first that it is DataRow or not like this.

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

Upvotes: 2

Related Questions