| User name | password |
|---|---|
| xyz | ******* |
| xyz | ******* |
Loading
| User name | password |
|---|---|
| xyz | ******* |
| xyz | ******* |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Feb 9, 2023, 8:30 AM EST
try this
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == 1 && e.Value != null) { e.Value = new string('*', e.Value.ToString().Length); e.FormattingApplied = true; } }Rajeesh MenothRank #118 · 18.4K reputationPosted Feb 9, 2023, 12:11 PM EST
Hi Nuru,
Similar SO solution:
https://stackoverflow.com/questions/31400177/masking-password-column-in-datagridview
Naimish MakwanaRank #324 · 7.7K reputationPosted Feb 9, 2023, 12:22 PM EST
Hello NURU,
As @Amit suggested you can do as below.
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == passwordColumnIndex && e.Value != null) { e.Value = new string('*', e.Value.ToString().Length); e.FormattingApplied = true; } }Also, You would need to attach this event handler to your DataGridView control in your form's constructor or
Loadevent, like this:Thanks
Naimish Makwana
Amit MohantyRank #112 · 20K reputationPosted Feb 9, 2023, 11:55 PM EST
if your application is in asp.net then try this
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Replace the password cell value with asterisks e.Row.Cells[1].Text = new string('*', e.Row.Cells[1].Text.Length); } }