You must Sign In to post a response.
  • Category: ASP.NET

    After click the edit button need to show the data in the textbox.

    After click the edit button need to show the data in the textbox.
    This is my structure

    Name : celv

    Designation : Staff

    Save Edit

    After click save me clear the data . after click the edit button I need to show the data again in textbox
    Name : celv

    Designation : Developer
    After edit the textbox again I click the edit button I need to update .
  • #767321
    Hi

    you can follow this steps for your task

    Step1

    Create the Table


    create table TblStaffdetails
    (
    Id int primary key identity(1,1),
    StaffName varchar(40),
    Designation varchar(40)
    )



    Step 2

    In the aspx Html Code this


    <form id="form1" runat="server">

    <table>
    <tr>
    <td>
    Name
    </td>
    <td>
    <asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
    </td>
    </tr>

    <tr>
    <td>
    Designation
    </td>
    <td>
    <asp:TextBox ID="TxtDesignation" runat="server"></asp:TextBox>
    </td>
    </tr>

    <tr>
    <td>
    <asp:Button ID="Save" runat="server" Text="Save" OnClick="Save_Click" />
    </td>
    <td>
    <asp:Button ID="Edit" runat="server" Text="Edit" OnClick="Edit_Click" />
    </td>
    </tr>

    </table>
    <asp:Label ID="lblMessage" runat="server"></asp:Label>

    </form>


    Step 3

    In this code for c# server side Code



    SqlConnection sqlcon = new SqlConnection("Data Source=JESUS-PC;Initial Catalog=userdb;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Save_Click(object sender, EventArgs e)
    {
    sqlcon.Open();
    SqlCommand sqlcmd = new SqlCommand("Insert into TblStaffdetails values('"+ TxtName.Text +"','"+ TxtDesignation.Text +"')", sqlcon);
    sqlcmd.ExecuteNonQuery();
    TxtName.Text = "";
    TxtDesignation.Text = "";
    lblMessage.Text = "Saved Data!....";
    }

    protected void Edit_Click(object sender, EventArgs e)
    {
    DataTable Dt = new DataTable();
    sqlcon.Open();
    SqlDataAdapter sqlcmd = new SqlDataAdapter("Select top 1 * from TblStaffdetails order by id desc", sqlcon);
    sqlcmd.Fill(Dt);
    if (Dt.Rows.Count > 0)
    {
    TxtDesignation.Text = Dt.DefaultView[0]["Designation"].ToString();
    TxtName.Text = Dt.DefaultView[0]["StaffName"].ToString();
    }


    }

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #767325
    Hi

    if you need same button show and update try this code



    protected void Edit_Click(object sender, EventArgs e)
    {
    if (TxtDesignation.Text == "" && TxtName.Text == "")
    {
    DataTable Dt = new DataTable();
    sqlcon.Open();
    SqlDataAdapter sqlcmd = new SqlDataAdapter("Select top 1 * from TblStaffdetails order by id desc", sqlcon);
    sqlcmd.Fill(Dt);
    if (Dt.Rows.Count > 0)
    {
    TxtDesignation.Text = Dt.DefaultView[0]["Designation"].ToString();
    TxtName.Text = Dt.DefaultView[0]["StaffName"].ToString();
    Session["id"] = Convert.ToInt32(Dt.DefaultView[0]["Id"]);
    }
    }

    else
    {
    sqlcon.Open();
    SqlCommand sqlcmd = new SqlCommand("Update TblStaffdetails set StaffName='" + TxtName.Text + "' where Id=" + Convert.ToInt32(Session["id"]) + "", sqlcon);
    sqlcmd.ExecuteNonQuery();
    }
    }


    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #767341
    Hi,

    What you tried so far, where did you struck?

    where did you showed those text's at present whether that is label control, while click edit you want that to showed up into textbox?

    if that is the requirement in your design you need to create label along with textbox control. and show or hide those controls based on your need, and assign the data to both controls at a time you just manipulate the controls for show / hide.

    Ex:

    PageLoad

    lbl.Text="text";
    txt1.Text="text"; //by default textbox should be visible false

    Edit button
    lbl.Visible=false;
    txt1.Visible=true;


    In the same manner you have to show/hide the controls.

    First try to implement then you can able to build it without any help from our end, without try don't expect solution from our end that will impact to your performance.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments