Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Thu, 3 Jul 2008 17:11:00 -0700,    group: microsoft.public.dotnet.framework.aspnet.webcontrols        back       


GridView with Password Field   
I have a gridview that contains a password field.  I’d like that password 
field to be in textmode = "Password" when in edit mode.  That way it will 
only show *'s.  How can I do that?
date: Thu, 3 Jul 2008 17:11:00 -0700   author:   Flyguy am

RE: GridView with Password Field   
Hi Flyguy,

Regarding on the your scenario that you want to use Password input field 
for Gridview editing, I think you can convert the certain column(in 
Gridview) to a TemplateField, thus you can customize the "EditTemplate" and 
use Password mode TextBox for editing data.

Also, for Password mode textbox, it has a natural limitation that we can 
not programmtically assign the value to it(through databinding expression) 
like normal mode textbox. One method I used is put an additional Label in 
that column which display the original value for the user's reference. Here 
is a example page I've used for test:

=========================
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="id" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:BoundField DataField="id" HeaderText="id" 
ReadOnly="True" 
                    SortExpression="id" />
              
                 <asp:TemplateField HeaderText="name" SortExpression="name">
                     <EditItemTemplate>
                     
                         <asp:TextBox ID="TextBox1" runat="server"  
Text='<%# Bind("name") %>'
                         TextMode="Password" ></asp:TextBox>
                         <br />original value:
                         <asp:Label ID="lblOld" runat="server"  Text='<%# 
Eval("name") %>' />
                     </EditItemTemplate>
                     <ItemTemplate>
                         <asp:Label ID="Label1" runat="server" Text='<%# 
Bind("name") %>'></asp:Label>
                     </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
=========================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and 
suggestions about how we can improve the support we provide to you. Please 
feel free to let my manager know what you think of the level of service 
provided. You can send feedback directly to my manager at: 
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to 
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues 
where an initial response from the community or a Microsoft Support 
Engineer within 1 business day is acceptable. Please note that each follow 
up response may take approximately 2 business days as the support 
professional working with you may need further investigation to reach the 
most efficient resolution. The offering is not appropriate for situations 
that require urgent, real-time or phone-based interactions or complex 
project analysis and dump analysis issues. Issues of this nature are best 
handled working with a dedicated Microsoft Support Engineer by contacting 
Microsoft Customer Support Services (CSS) at 
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: =?Utf-8?B?Rmx5Z3V5?= <flyguy@nospam.nospam>
>Subject: GridView with Password Field
>Date: Thu, 3 Jul 2008 17:11:00 -0700

>
>I have a gridview that contains a password field.  I’d like that 
password 
>field to be in textmode = "Password" when in edit mode.  That way it will 
>only show *'s.  How can I do that?
>
date: Fri, 04 Jul 2008 02:56:35 GMT   author:   (Steven Cheng [MSFT])

RE: GridView with Password Field   
Steven,

This is great stuff.  My only question is how I get the value that the user 
enters into the textbox.  I have no idea how I reference the data in my code.

"Steven Cheng [MSFT]" wrote:

> Hi Flyguy,
> 
> Regarding on the your scenario that you want to use Password input field 
> for Gridview editing, I think you can convert the certain column(in 
> Gridview) to a TemplateField, thus you can customize the "EditTemplate" and 
> use Password mode TextBox for editing data.
> 
> Also, for Password mode textbox, it has a natural limitation that we can 
> not programmtically assign the value to it(through databinding expression) 
> like normal mode textbox. One method I used is put an additional Label in 
> that column which display the original value for the user's reference. Here 
> is a example page I've used for test:
> 
> =========================
>  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
>             DataKeyNames="id" DataSourceID="SqlDataSource1">
>             <Columns>
>                 <asp:CommandField ShowEditButton="True" />
>                 <asp:BoundField DataField="id" HeaderText="id" 
> ReadOnly="True" 
>                     SortExpression="id" />
>               
>                  <asp:TemplateField HeaderText="name" SortExpression="name">
>                      <EditItemTemplate>
>                      
>                          <asp:TextBox ID="TextBox1" runat="server"  
> Text='<%# Bind("name") %>'
>                          TextMode="Password" ></asp:TextBox>
>                          <br />original value:
>                          <asp:Label ID="lblOld" runat="server"  Text='<%# 
> Eval("name") %>' />
>                      </EditItemTemplate>
>                      <ItemTemplate>
>                          <asp:Label ID="Label1" runat="server" Text='<%# 
> Bind("name") %>'></asp:Label>
>                      </ItemTemplate>
>                 </asp:TemplateField>
>             </Columns>
>         </asp:GridView>
> =========================
> 
> Hope this helps.
> 
> Sincerely,
> 
> Steven Cheng
> 
> Microsoft MSDN Online Support Lead
> 
> 
> Delighting our customers is our #1 priority. We welcome your comments and 
> suggestions about how we can improve the support we provide to you. Please 
> feel free to let my manager know what you think of the level of service 
> provided. You can send feedback directly to my manager at: 
> msdnmg@microsoft.com.
> 
> ==================================================
> Get notification to my posts through email? Please refer to 
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> 
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues 
> where an initial response from the community or a Microsoft Support 
> Engineer within 1 business day is acceptable. Please note that each follow 
> up response may take approximately 2 business days as the support 
> professional working with you may need further investigation to reach the 
> most efficient resolution. The offering is not appropriate for situations 
> that require urgent, real-time or phone-based interactions or complex 
> project analysis and dump analysis issues. Issues of this nature are best 
> handled working with a dedicated Microsoft Support Engineer by contacting 
> Microsoft Customer Support Services (CSS) at 
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
> 
> 
> --------------------
> >From: =?Utf-8?B?Rmx5Z3V5?= <flyguy@nospam.nospam>
> >Subject: GridView with Password Field
> >Date: Thu, 3 Jul 2008 17:11:00 -0700
> 
> >
> >I have a gridview that contains a password field.  I’d like that 
> password 
> >field to be in textmode = "Password" when in edit mode.  That way it will 
> >only show *'s.  How can I do that?
> >
> 
>
date: Sat, 5 Jul 2008 16:44:00 -0700   author:   Flyguy am

RE: GridView with Password Field   
Thanks for your reply Flyguy,

As for the TextBox in template field , if you use "Bind" expression and 
datasource control, it automatically provide two-way databinding function. 
Are you using custom code to do the database updating(so that you need to 
manually get reference to the data in textbox)?

generally, if you use the databound column or standard databinding 
expression(two-way) in template, you can register "RowUpdating" event of 
gridview and check those fields in the parameter:

=================================
 protected void GridView1_RowUpdating(object sender, 
GridViewUpdateEventArgs e)
    {
        //e.Keys;
        //e.OldValues;
       // e.NewValues;
    }
=========================

Please feel free to let me know if you have any other questions.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and 
suggestions about how we can improve the support we provide to you. Please 
feel free to let my manager know what you think of the level of service 
provided. You can send feedback directly to my manager at: 
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to 
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: =?Utf-8?B?Rmx5Z3V5?= <flyguy@nospam.nospam>
>References:   
<3$#jZGY3IHA.3784@TK2MSFTNGHUB02.phx.gbl>
>Subject: RE: GridView with Password Field
>Date: Sat, 5 Jul 2008 16:44:00 -0700

>Steven,
>
>This is great stuff.  My only question is how I get the value that the 
user 
>enters into the textbox.  I have no idea how I reference the data in my 
code.
>
>"Steven Cheng [MSFT]" wrote:
>
>> Hi Flyguy,
>> 
>> Regarding on the your scenario that you want to use Password input field 
>> for Gridview editing, I think you can convert the certain column(in 
>> Gridview) to a TemplateField, thus you can customize the "EditTemplate" 
and 
>> use Password mode TextBox for editing data.
>> 
>> Also, for Password mode textbox, it has a natural limitation that we can 
>> not programmtically assign the value to it(through databinding 
expression) 
>> like normal mode textbox. One method I used is put an additional Label 
in 
>> that column which display the original value for the user's reference. 
Here 
>> is a example page I've used for test:
>> 
>> =========================
>>  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
>>             DataKeyNames="id" DataSourceID="SqlDataSource1">
>>             <Columns>
>>                 <asp:CommandField ShowEditButton="True" />
>>                 <asp:BoundField DataField="id" HeaderText="id" 
>> ReadOnly="True" 
>>                     SortExpression="id" />
>>               
>>                  <asp:TemplateField HeaderText="name" 
SortExpression="name">
>>                      <EditItemTemplate>
>>                      
>>                          <asp:TextBox ID="TextBox1" runat="server"  
>> Text='<%# Bind("name") %>'
>>                          TextMode="Password" ></asp:TextBox>
>>                          <br />original value:
>>                          <asp:Label ID="lblOld" runat="server"  
Text='<%# 
>> Eval("name") %>' />
>>                      </EditItemTemplate>
>>                      <ItemTemplate>
>>                          <asp:Label ID="Label1" runat="server" Text='<%# 
>> Bind("name") %>'></asp:Label>
>>                      </ItemTemplate>
>>                 </asp:TemplateField>
>>             </Columns>
>>         </asp:GridView>
>> =========================
>> 
>> Hope this helps.
>> 
>> Sincerely,
>> 
>> Steven Cheng
>> 
>> Microsoft MSDN Online Support Lead
>>
date: Mon, 07 Jul 2008 02:12:30 GMT   author:   (Steven Cheng [MSFT])

RE: GridView with Password Field   
I am using custom code to do the database updating (so I do need to manually 
get a reference to the data in textbox).

"Steven Cheng [MSFT]" wrote:

> Thanks for your reply Flyguy,
> 
> As for the TextBox in template field , if you use "Bind" expression and 
> datasource control, it automatically provide two-way databinding function. 
> Are you using custom code to do the database updating(so that you need to 
> manually get reference to the data in textbox)?
> 
> generally, if you use the databound column or standard databinding 
> expression(two-way) in template, you can register "RowUpdating" event of 
> gridview and check those fields in the parameter:
> 
> =================================
>  protected void GridView1_RowUpdating(object sender, 
> GridViewUpdateEventArgs e)
>     {
>         //e.Keys;
>         //e.OldValues;
>        // e.NewValues;
>     }
> =========================
> 
> Please feel free to let me know if you have any other questions.
> 
> Sincerely,
> 
> Steven Cheng
> 
> Microsoft MSDN Online Support Lead
> 
> 
> Delighting our customers is our #1 priority. We welcome your comments and 
> suggestions about how we can improve the support we provide to you. Please 
> feel free to let my manager know what you think of the level of service 
> provided. You can send feedback directly to my manager at: 
> msdnmg@microsoft.com.
> 
> ==================================================
> Get notification to my posts through email? Please refer to 
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> 
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
> 
> 
> --------------------
> >From: =?Utf-8?B?Rmx5Z3V5?= <flyguy@nospam.nospam>
> >References:   
> <3$#jZGY3IHA.3784@TK2MSFTNGHUB02.phx.gbl>
> >Subject: RE: GridView with Password Field
> >Date: Sat, 5 Jul 2008 16:44:00 -0700
> 
> >Steven,
> >
> >This is great stuff.  My only question is how I get the value that the 
> user 
> >enters into the textbox.  I have no idea how I reference the data in my 
> code.
> >
> >"Steven Cheng [MSFT]" wrote:
> >
> >> Hi Flyguy,
> >> 
> >> Regarding on the your scenario that you want to use Password input field 
> >> for Gridview editing, I think you can convert the certain column(in 
> >> Gridview) to a TemplateField, thus you can customize the "EditTemplate" 
> and 
> >> use Password mode TextBox for editing data.
> >> 
> >> Also, for Password mode textbox, it has a natural limitation that we can 
> >> not programmtically assign the value to it(through databinding 
> expression) 
> >> like normal mode textbox. One method I used is put an additional Label 
> in 
> >> that column which display the original value for the user's reference. 
> Here 
> >> is a example page I've used for test:
> >> 
> >> =========================
> >>  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
> >>             DataKeyNames="id" DataSourceID="SqlDataSource1">
> >>             <Columns>
> >>                 <asp:CommandField ShowEditButton="True" />
> >>                 <asp:BoundField DataField="id" HeaderText="id" 
> >> ReadOnly="True" 
> >>                     SortExpression="id" />
> >>               
> >>                  <asp:TemplateField HeaderText="name" 
> SortExpression="name">
> >>                      <EditItemTemplate>
> >>                      
> >>                          <asp:TextBox ID="TextBox1" runat="server"  
> >> Text='<%# Bind("name") %>'
> >>                          TextMode="Password" ></asp:TextBox>
> >>                          <br />original value:
> >>                          <asp:Label ID="lblOld" runat="server"  
> Text='<%# 
> >> Eval("name") %>' />
> >>                      </EditItemTemplate>
> >>                      <ItemTemplate>
> >>                          <asp:Label ID="Label1" runat="server" Text='<%# 
> >> Bind("name") %>'></asp:Label>
> >>                      </ItemTemplate>
> >>                 </asp:TemplateField>
> >>             </Columns>
> >>         </asp:GridView>
> >> =========================
> >> 
> >> Hope this helps.
> >> 
> >> Sincerely,
> >> 
> >> Steven Cheng
> >> 
> >> Microsoft MSDN Online Support Lead
> >> 
> 
>
date: Sun, 6 Jul 2008 20:36:01 -0700   author:   Flyguy am

RE: GridView with Password Field   
Thanks for your reply Flyguy,

Yes, if you manually do the update, you need to extract the values(the user 
enter for edit/update) and call ADO.NET functions to do the data accessing. 
As I mentioned in previous reply, for GridView, the "RowUpdating" is the 
proper place where you put your code which extract values from GridView 
line and do the updating. For example:

#I assume you use <%# Eval("") %> expression to bind data and the following 
is the EditTemplate:
=================

                 <asp:TemplateField HeaderText="name" SortExpression="name">
                     <EditItemTemplate>
                       <asp:TextBox ID="txtPassword" runat="server"  
TextMode="Password" ></asp:TextBox>
                      ....................
                     </EditItemTemplate>
                  ..........................
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
=====================

You can use the below code to extract value from the password textbox:
=========
    protected void GridView1_RowUpdating(object sender, 
GridViewUpdateEventArgs e)
    {
        TextBox txtPass = 
GridView1.Rows[GridView1.EditIndex].FindControl("txtPassword") as TextBox;

        if(txtPass!= null)
            Response.Write("<br/>you enter: " + txtPass.Text + " as 
password.");

//do your data updating code here


        e.Cancel = true;
    }
}


==================

it also applies if you have more controls inside the template. Just Find 
them via their ID.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and 
suggestions about how we can improve the support we provide to you. Please 
feel free to let my manager know what you think of the level of service 
provided. You can send feedback directly to my manager at: 
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to 
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
>References:   
<3$#jZGY3IHA.3784@TK2MSFTNGHUB02.phx.gbl> 
 

>Subject: RE: GridView with Password Field
>Date: Sun, 6 Jul 2008 20:36:01 -0700
>
> I am using custom code to do the database updating (so I do need to 
manually 
>get a reference to the data in textbox).
>
>"Steven Cheng [MSFT]" wrote:
>
>> Thanks for your reply Flyguy,
>> 
>> As for the TextBox in template field , if you use "Bind" expression and 
>> datasource control, it automatically provide two-way databinding 
function. 
>> Are you using custom code to do the database updating(so that you need 
to 
>> manually get reference to the data in textbox)?
>> 
>> generally, if you use the databound column or standard databinding 
>> expression(two-way) in template, you can register "RowUpdating" event of 
>> gridview and check those fields in the parameter:
>> 
>> =================================
>>  protected void GridView1_RowUpdating(object sender, 
>> GridViewUpdateEventArgs e)
>>     {
>>         //e.Keys;
>>         //e.OldValues;
>>        // e.NewValues;
>>     }
>> =========================
>> 
>> Please feel free to let me know if you have any other questions.
>> 
>> Sincerely,
>> 
>> Steven Cheng
>> 
>> Microsoft MSDN Online Support Lead
>> 
>> 
>> Delighting our customers is our #1 priority. We welcome your comments 
and 
>> suggestions about how we can improve the support we provide to you. 
Please 
>> feel free to let my manager know what you think of the level of service 
>> provided. You can send feedback directly to my manager at: 
>> msdnmg@microsoft.com.
>> 
>> ==================================================
>> Get notification to my posts through email? Please refer to 
>> 
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>> ications.
>>
date: Mon, 07 Jul 2008 10:37:06 GMT   author:   (Steven Cheng [MSFT])

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us