Edit a field on the page

Hello, suppose I want to edit user name on the page. The attached image is a snapshot. user nameCurrently it is a label there.
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>General user information</div>
<p></p>
<table cellpadding="2">
   <tr>
      <td width="130">UserName:</td>
      <td width="300"><asp:Literal runat="server" ID="lblUserName" /></td>
   </tr>
   <tr>
      <td>E-mail address:</td>
      <td><asp:HyperLink ID="lnkEmailAddress" runat="server" /></td>
   </tr>
   <tr>
      <td>Registered:</td>
      <td><asp:Literal  ID="lblRegistered" runat="server" /></td>
   </tr>

Open in new window

I want that I can control the user name then save it to the database.
Any suggestion?
Should I change the label to text box?
I appreciate a piece of code.
zhshqzycAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Manoj PatilSr. Software EngineerCommented:
Yes you can change the label to the TextBox. Set TextBox by Default disable.  Give CheckBox like "Edit UserName"
And on Click of that enable TextBox
Use following script to Enable TextBox

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
        function ToggleTextBox(CheckBox, TextBoxID) {
            var TextBox = document.getElementById(TextBoxID);
            if (CheckBox.checked) {
                TextBox.disabled = false;                
            }
            else {
                TextBox.disabled = true;                
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBox ID="cb1" runat="server" onclick="ToggleTextBox(this,'txt1')" />
        <asp:TextBox ID="txt1" runat="server" Enabled="false"></asp:TextBox>
    </div>
    </form>
</body>
</html>

Open in new window


And Save it from your Save Button


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zhshqzycAuthor Commented:
Probably I need edit  and save it in the database.
Can I use a gridview to display plus edit function?
Like this,
but I don't want to edit the entire table, I just want to implement a specific user.
0
zhshqzycAuthor Commented:
Ignore the above one. Please see the attached file. editWhat I want is that I can edit the user name and click appove box then save it. The user will received an confirmation email.

Thanks for help.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Manoj PatilSr. Software EngineerCommented:
Yes,  you can use GridView to Edit and save the Data in Database.
Just Enable Edit, Enable Update, Enable Delete Properties of GridView to do so.

If you want to edit only specific column then you can achieve it as follows. When you enable Edit, Update, Delete properties then GridView looks like following.

SAMPLE GRID VIEW :

<asp:GridView ID="GridViewEmployee" runat="server" AutoGenerateColumns="False"

        ShowFooter="True" onrowcancelingedit="GridViewEmployee_RowCancelingEdit"

        onrowediting="GridViewEmployee_RowEditing"

        onrowupdating="GridViewEmployee_RowUpdating"

        onrowdeleting="GridViewEmployee_RowDeleting">

    <Columns>

        <asp:TemplateField HeaderText="Employee Name">

            <EditItemTemplate>

                <asp:TextBox ID="TextBoxEditEmployee" runat="server" Text='<%# Bind("Employees") %>'/>

            </EditItemTemplate>

            <ItemTemplate>

                <asp:Label ID="LabelEmployee" runat="server" Text='<%# Bind("Employees") %>'/>

            </ItemTemplate>

            <FooterTemplate>

                <asp:TextBox ID="TextBoxEmployee" runat="server"/>

            </FooterTemplate>

        </asp:TemplateField >

        <asp:TemplateField HeaderText="Position">

            <EditItemTemplate>

                <asp:TextBox ID="TextBoxEditPosition" runat="server" Text='<%# Bind("Position") %>'/>

            </EditItemTemplate>

            <ItemTemplate>

                <asp:Label ID="LabelPosition" runat="server" Text='<%# Bind("Position") %>'/>

            </ItemTemplate>

            <FooterTemplate>

                    <asp:TextBox ID="TextBoxPosition" runat="server"/>

            </FooterTemplate>

        </asp:TemplateField>

        <asp:TemplateField HeaderText="Team Name">

            <EditItemTemplate>

                <asp:TextBox ID="TextBoxEditTeam" runat="server" Text='<%# Bind("Team") %>'/>

            </EditItemTemplate>

            <ItemTemplate>

                <asp:Label ID="LabelTeam" runat="server" Text='<%# Bind("Team") %>'/>

            </ItemTemplate>

            <FooterTemplate>

                    <asp:TextBox ID="TextBoxTeam" runat="server"/>

            </FooterTemplate>

        </asp:TemplateField>

        <asp:TemplateField HeaderText="Employee ID">

            <ItemTemplate>

                <asp:Label ID="LabelID" runat="server" Text='<%# Bind("Id") %>'/>

            </ItemTemplate>

            <FooterTemplate>

                <asp:Button ID="Button1" runat="server" Text="Add New" OnClick="Button1_Click" />

            </FooterTemplate>

        </asp:TemplateField>

        <asp:CommandField ShowEditButton="True" ShowDeleteButton />

    </Columns>

    </asp:GridView>

Open in new window



If you want to update only username then in <EditItemTemplate> tab, there is an TextBox field with Text property like        
 Text='<%# Bind("UserName") %>'  

The fields which you don't want to update, in this case
In <EditItemTemplate> for that specific column  just replace TextBox with Label. That's it !!!

When you click on Edit button then it show the TextBox for which you need to update the Data and the fields which you have set to Labels will not allow to change the Data
Try this.
0
zhshqzycAuthor Commented:
If using GridView, it will display the whole table and there are Edit buttons on the left side.
However if I only want to display a specific user information as the image below. I don't want Edit butthon showing up, in another word, I do not use GridView.
 user infoThen how?
0
Manoj PatilSr. Software EngineerCommented:
If you don't want to use GridView then follow the steps which I had told you in first comment
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.