This is a migrated thread and some comments may be shown as answers.

Format text password style (*****)

4 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 30 Nov 2013, 11:05 PM
I have a radGrid with a column which is password.
I would like the password filed in both edit and grid mode to hide the password with ********.

This is the column:
<telerik:GridTemplateColumn HeaderText="Password"  UniqueName="pass" DataField="pass" SortExpression="Pass">
                       <ItemTemplate>
                           <asp:Label ID="lblpass" runat="server" Text='<%# Eval("pass")  %>' width="100px"></asp:Label>
                       </ItemTemplate>
                       <EditItemTemplate>
                           <telerik:RadTextBox ID="txtpass" Width="300px" runat="server" Text='<%# Bind("pass") %>' >
                           </telerik:RadTextBox>
                       </EditItemTemplate>
                   </telerik:GridTemplateColumn>
How can I achieve to apply such format to the password data?
Thanks,
Felice

4 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Dec 2013, 06:45 AM
Hello,

<telerik:GridTemplateColumn HeaderText="Name" UniqueName="Name" DataField="Name" SortExpression="Name">
                       <ItemTemplate>
                           <asp:Label ID="lblpass" runat="server" Text='<%# CustomMethod.ConvertIntoPassword(Convert.ToString(Eval("Name")))  %>' Width="100px"></asp:Label>
                       </ItemTemplate>
                       <EditItemTemplate>
                           <telerik:RadTextBox ID="txtpass" Width="300px" runat="server" Text='<%# CustomMethod.ConvertIntoPassword(Convert.ToString(Eval("Name")))  %>'>
                           </telerik:RadTextBox>
                       </EditItemTemplate>
                   </telerik:GridTemplateColumn>

public static class CustomMethod
{
    public static string ConvertIntoPassword(string str)
    {
        string strPass = string.Empty;
 
        for (int i = 1; i < Convert.ToString(str).Length; i++)
            strPass += "*";
 
        return strPass;
    }
}

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Felice
Top achievements
Rank 1
answered on 03 Dec 2013, 02:51 PM
Dear Jayesh,
thanks for the snippet but it is causing a lot of errors:

Error 2 Telerik.Web.UI.GridColumnCollection can have only elements type 'Telerik.Web.UI.GridColumn'. 'ItemTemplate' is type 'System.Web.UI.HtmlControls.HtmlGenericControl'.

Error 3 Telerik.Web.UI.GridColumnCollection can have only elements type
'Telerik.Web.UI.GridColumn'. 'asp:Label' is type 'System.Web.UI.WebControls.Label'.


Error 4 Telerik.Web.UI.GridColumnCollection can have only elements type
'Telerik.Web.UI.GridColumn'. 'EditItemTemplate' is type 'System.Web.UI.HtmlControls.HtmlGenericControl'.


Error 5 Telerik.Web.UI.GridColumnCollection can have only elements type
'Telerik.Web.UI.GridColumn'. 'telerik:RadTextBox' is type 'Telerik.Web.UI.RadTextBox'.


Error 6 The letteral content ('<telerik:GridTemplateColumn HeaderText="Name" UniqueName="Name"DataField="Name" SortExpression="Name">                                                      </asp:Label>                         </ItemTemplate>                                                                                   </telerik:RadTextBox>                         </EditItemTemplate>                     </telerik:GridTemplateColumn>') is not allowed in  'Telerik.Web.UI.GridColumnCollection'


0
Accepted
Princy
Top achievements
Rank 2
answered on 04 Dec 2013, 04:11 AM
Hi Felice,

Please try the following code snippet. If it cause any issue, please provide your full code snippet.

ASPX:
<telerik:GridTemplateColumn HeaderText="Password" UniqueName="pass" DataField="Password">
<ItemTemplate>
    <asp:Label ID="lblpass" runat="server" Text='<%# Eval("Password")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
    <telerik:RadTextBox ID="txtpass" Width="300px" runat="server" AutoPostBack="true" Text='<%# Bind("Password") %>' OnTextChanged="txtpass_TextChanged">
    </telerik:RadTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    //To change the password in * format in view mode
    if (e.Item is GridDataItem)
    {
        GridDataItem data = (GridDataItem)e.Item;
        Label lbl = (Label)data.FindControl("lblpass");
        string value = lbl.Text;
        lbl.Text = "";
        foreach (char c in value)
         lbl.Text += "*";
    }
 
    //To change the password in * format in edit mode
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem edit = (GridEditableItem)e.Item;
        RadTextBox txt = (RadTextBox)edit.FindControl("txtpass");
        string value = txt.Text;
        txt.Text = "";
        foreach (char c in value)
        txt.Text += "*";
    }
}
protected void txtpass_TextChanged(object sender, EventArgs e)
{
    //To change the password in * format after entering in textbox in editmode
    RadTextBox paswordtxt = (RadTextBox)sender;
    string value = paswordtxt.Text;
    paswordtxt.Text = "";
    foreach (char c in value)
    paswordtxt.Text += "*";
}

Thanks,
Princy
0
Felice
Top achievements
Rank 1
answered on 04 Dec 2013, 07:45 AM
Dear Princy,
thanks a lot for your help.
Your snippet works perfectly. Problem solved.
Thanks,
Felice
Tags
Grid
Asked by
Felice
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Felice
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or