Using JavaScript to format expression in a ASP.NET DataGrid text field?

Can someone show me how to either write a function or use the DataGrid formatting expression to format a text field?  I have a text field in a datagrid that I want to replace the first 3 chars with "***".  Can this be done using the DataGrid formatting expression? or do I need to write a JAvascript function and use a template column?  If so, can someone, please provide me an example.

<asp:BoundColumn DataField="ACCTNUM" SortExpression="c.ACCTNUM" HeaderText="Acct Num">
<HeaderStyle Width="10%"></HeaderStyle>
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jens FiedererTest Developer/ValidatorCommented:
Couple of questions:

1) Do you want the DISPLAY to look like "***" but the actual value to be something different, or do you just want to assure that the first three characters are actually "***".

2) Does this need to be happening AS THE USER TYPES, or just when the page is first presented.

3) what happens when there are fewer than 3 characters?

HojoformoAuthor Commented:
1.  The last three chars of the actual value needs to be replaced with "***".  So the account number would look like:

2. Only when the page loads.  The window just displays data with links.  There are no text boxes.  

3.  There will never be fewer than 3 chars but if so than it will be all ***.

I hope you can help.  Thanks.
Jens FiedererTest Developer/ValidatorCommented:
A template column will do just fine.

Trivial example:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="replace.aspx.vb" Inherits="replace" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <asp:DataGrid runat="server" ID=dg1 AutoGenerateColumns="False">
                    <asp:Label runat="server" ><%#System.Text.RegularExpressions.Regex.Replace(DataBinder.Eval(Container, "Dataitem"), "...$", "***")%></asp:Label>

with codebehind:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        dg1.DataSource = New System.Collections.Generic.List(Of Integer)(New Integer() {5000, 5001, 60001})
    End Sub
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Jens FiedererTest Developer/ValidatorCommented:
Essentially you are giving an expressing that REPLACES the last three characters with three stars.
Jens FiedererTest Developer/ValidatorCommented:
On the other hand, this cannot be accomplished with a simple custom format string (there is no '*' placeholder).
HojoformoAuthor Commented:
Thanks jensfiederer!  I like your suggestion but when I try it I all ways get a parse error:

"CS1502: The best overloaded method match for 'System.Text.RegularExpressions.Regex.Replace(string, string, string)' has some invalid arguments

<asp:LinkButton ID="m_JobDescButton" Runat="server" CommandName="ShowDetails">
<%# System.Text.RegularExpressions.Regex.Replace(DataBinder.Eval(Container, "CSSACCTNUM"), "...$", "***")%>
Jens FiedererTest Developer/ValidatorCommented:
Well, Replace(string, string, string) is what we WANT to be using, and we KNOW  "...$", "***" work (my example functions - you might want to try it on your machine to verify, but it looks like it is trying to do the right thing), so the problem is probably
DataBinder.Eval(Container, "CSSACCTNUM")

what datatype does that turn out to be?

You might want to try just
<asp:LinkButton ID="m_JobDescButton" Runat="server" CommandName="ShowDetails">
<%#DataBinder.Eval(Container, "CSSACCTNUM) %>


<asp:LinkButton ID="m_JobDescButton" Runat="server" CommandName="ShowDetails">
<%#DataBinder.Eval(Container, "CSSACCTNUM).GetType() %>

to find what you are working with.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jens FiedererTest Developer/ValidatorCommented:
Thanks - that gets me my Javascript certification.  A bit funny to break 50,000 on what really turns out to be an ASP.NET question!
(I was already up there in .NET, ASP.NET, and VB.NET)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.