Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

i am using the gridview with ItemTemplate Field. in which there is a password column,so i just take label and set it text as *****(star) so no one can read.

but when i edit any record using edit property the password value become null, and i want to display as **** when edit.because not in all case edit the password it may be edit the name of user. so what can i do....
XML
<asp:TemplateField HeaderText="Password">

           <ItemTemplate>
                <asp:Label runat="server" ID="password1" Text="*******"/>
           </ItemTemplate>

           <EditItemTemplate>
                  <asp:TextBox runat="server" ID="password" Text='<%#Eval("password") %>' ValidationGroup="v1" TextMode="Password" Columns="10" />
                  <asp:RequiredFieldValidator runat="server" ID="req14" ControlToValidate="password" ErrorMessage="*" ValidationGroup="v1" />
           </EditItemTemplate>
        </asp:TemplateField>

row updating....
C#
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
TextBox password = (TextBox)row.FindControl("password");
GridView1.EditIndex = -1;
and update query i use..

but in textbox of password become null and i want to display *** by default. and it may be changed when admin click on textbox of password.

so, this is my problem...

Please Help Me...
Thankss...
Mitesh
Posted
Updated 14-May-12 20:23pm
v2

1 solution

What kind of UI or requirement asks Password to be one of the grid columns for editing? Password is suppose to be user specific and confidential - even to admins.

I would never use such application where my password is displayed to any other user in any format. Even if you succeed in keeping it as ****, I don't see why this is needed in the grid in first place.

Further, If you want to give edit password functionality some how, then you should give a UI where you also confirm the password entered. So, instead of above UI, I would suggest a context menu to change password, which would open a dialog where new password and confirm new password will be entered and saved for the selected user.
 
Share this answer
 
Comments
[no name] 15-May-12 2:50am    
but it is not possible to give some default value to the textbox when edit button is clicked.
e.g. txtpass.attributes.add["xx","***"];
some like that...
Sandeep Mewara 15-May-12 11:23am    
This is the way to retain password field:
txtPassword.Attributes["value"]= txtPassword.Text OR txtPassword.Attributes.Add("value", "*****");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900