GridView custom column display.

  • Thread starter Thread starter typingcat
  • Start date Start date
T

typingcat

Hello.
It was very easy to display the contents of a table in a database using
the GridView. But I wonder if this is possible. The field 'e-mail'
contains original e-mail addresses, but for security reason, I would
like to omit some part of them. For example,

Original field data : (e-mail address removed)
Displayed in GridView : (e-mail address removed) (replace 3 characters
left side of @)

If I use the old way (manually querying and outputting using
<table>...) it will take some time but not a hard job. I just want to
know wheter I can do this with GridView or not. Please let me know if
you have any idea. Thank you.
 
As wating for a nice reply, I tried to solve it myself.
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 1)
{
StringBuilder temp=new StringBuilder(e.Row.Cells[1].Text);
int whereisat = e.Row.Cells[1].Text.IndexOf("@")-1;
for(int i=0; i<3; i++)
{
if (whereisat < 1)
break;
temp[whereisat - i] = '.';
}
e.Row.Cells[1].Text = temp.ToString();
}
}
where Cells[1] is the e-mail field. It worked as I expected but is
there any better way to do this job?
 
This is one of the correct ways.

Eliyahu

As wating for a nice reply, I tried to solve it myself.
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 1)
{
StringBuilder temp=new StringBuilder(e.Row.Cells[1].Text);
int whereisat = e.Row.Cells[1].Text.IndexOf("@")-1;
for(int i=0; i<3; i++)
{
if (whereisat < 1)
break;
temp[whereisat - i] = '.';
}
e.Row.Cells[1].Text = temp.ToString();
}
}
where Cells[1] is the e-mail field. It worked as I expected but is
there any better way to do this job?

Hello.
It was very easy to display the contents of a table in a database using
the GridView. But I wonder if this is possible. The field 'e-mail'
contains original e-mail addresses, but for security reason, I would
like to omit some part of them. For example,

Original field data : (e-mail address removed)
Displayed in GridView : (e-mail address removed) (replace 3 characters
left side of @)

If I use the old way (manually querying and outputting using
<table>...) it will take some time but not a hard job. I just want to
know wheter I can do this with GridView or not. Please let me know if
you have any idea. Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top