Password Box in GridView

5 posts, 1 answers
  1. Bryan Johnson
    Bryan Johnson avatar
    18 posts
    Member since:
    May 2010

    Posted 31 Aug 2010 Link to this post

    I'm using a password box inside of a RadGridView cell.  I'm also using buttons with the gridview commands to control the editing behavior of the grid.  It works pretty well except that if the only field changed is the password field, the 'Save Insert/Edit' button is not enabled.  I actually have to edit another field in the same row and then the button becomes enabled and I can save the changes.  The updated password is then written to the database via a web service.  Is there a different way to bind the password box to the grid cell so that it works better with the gridview command buttons?  I've included my code below:

    <telerik:GridViewDataColumn DataMemberBinding="{Binding password, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Header="Password">
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <PasswordBox Password="{Binding password, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" />
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
    </telerik:GridViewDataColumn>
  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 02 Sep 2010 Link to this post

    Hi Bryan Johnson,

    The button will become enabled only when the grid is in edit mode. Clicking in the password box which is in the CellTemplate will not enter the edit mode of the grid.

    I suggest that you try the following:

    1. Set the Snippet EditTriggers="CellClick" property of the gridview

    2. Define the column like this:

    <telerik:GridViewDataColumn DataMemberBinding="{Binding password}"
                                Header="Password">
        <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="**********" />
            </DataTemplate>
        </telerik:GridViewDataColumn.CellTemplate>
        <telerik:GridViewDataColumn.CellEditTemplate>
            <DataTemplate>
                <PasswordBox Password="{Binding password, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" />
            </DataTemplate>
        </telerik:GridViewDataColumn.CellEditTemplate>
    </telerik:GridViewDataColumn>

    Hope this helps.

    All the best,
    Veselin Vasilev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Bryan Johnson
    Bryan Johnson avatar
    18 posts
    Member since:
    May 2010

    Posted 02 Sep 2010 Link to this post

    That worked.  Thanks!
  4. Joris
    Joris avatar
    3 posts
    Member since:
    Jul 2012

    Posted 14 Aug 2012 Link to this post

    Hi all, first of all thank you for posting this question and reply. This was a great help.

    Unfortunately I have a small problem with this when validating the value. 
    In VB if I ask Len(e.NewValue.ToSting I get a Null value in return.

    Cloud you please advise how to get the value from the passwordbox.

    Thanks in advance,
    Joris

    I've found it.

    e.EditingElement.Password

    Didn't think of looking into the object itself.
  5. Brian
    Brian avatar
    10 posts
    Member since:
    Jul 2012

    Posted 06 Nov 2012 Link to this post

    The solution provided above by Veselin unfortunately does not work any more, as the WPF PasswordBox cannot be data bound any more due to security concerns. Is there another angle I can use to achieve the same results?

    BP
Back to Top