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

    How to insert records into database using Popup Extender

    Hi Developers ,

    i want to insert record into database using POPUP menu in asp.net . I have done update so could anyone please help me to how am done this task . Today is last day so only i am ask .

    Thanks with
    Paul.S
  • #764841
    Hi,

    I assume your pop extender is nothing but another .aspx page. If that is the case there is no difference in the code which you normally use to save the data in DB.

    If I misunderstood your issue then please let me know.


    Regards,
    Asheej T K
    Microsoft MVP[ASP.NET/IIS]
    DotNetSpider MVM

  • #764843
    If i change the code update to insert na my problem will be solved ah. or i need to change anything else Mr.Asheej

    Thanks with
    Paul.S

  • #764851

    what is code right now ? we can not assume anything with out looking at your code, please post your code so that we can help you better in order to resolve your issue,
    If UPDATE is proper then you can make INSERT also, as Asheej told popup0 Extender is an ASPX page, you can simple code there for INSERT


    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764854
    This is my source code for updated records in popup extender.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.OleDb;
    using System.Data;
    using System.Configuration;
    using System.Drawing;

    public partial class Popup : System.Web.UI.Page
    {
    OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    BindGridData();
    }
    }
    protected void BindGridData()
    {
    con.Open();
    OleDbCommand cmd = new OleDbCommand("Select * from Employee_Details", con);
    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    gvdetails.DataSource = dt;
    gvdetails.DataBind();
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
    con.Open();
    OleDbCommand cmd = new OleDbCommand("update Employee_Details set FirstName=@FirstName,LastName=@LastName, City=@City,Designation=@Designation where Id=@Id", con);
    cmd.Parameters.AddWithValue("@FirstName", txtfname.Text);
    cmd.Parameters.AddWithValue("@LastName", txtlname.Text);
    cmd.Parameters.AddWithValue("@City", txtCity.Text);
    cmd.Parameters.AddWithValue("@Designation", txtDesg.Text);
    cmd.Parameters.AddWithValue("@UserId", Convert.ToInt32(lblID.Text));
    cmd.ExecuteNonQuery();
    con.Close();
    lblresult.Text = lblusername.Text + " Details Updated Successfully";
    lblresult.ForeColor = Color.Green;
    BindGridData();
    }
    protected void imgbtn_Click(object sender, ImageClickEventArgs e)
    {
    ImageButton btndetails = sender as ImageButton;
    GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
    lblID.Text = gvdetails.DataKeys[gvrow.RowIndex].Value.ToString();
    lblusername.Text = gvrow.Cells[1].Text;
    txtfname.Text = gvrow.Cells[2].Text;
    txtlname.Text = gvrow.Cells[3].Text;
    txtCity.Text = gvrow.Cells[4].Text;
    txtDesg.Text = gvrow.Cells[5].Text;
    this.ModalPopupExtender1.Show();
    }
    }

    I need justhow to insert records also Mr.Prasad

  • #764859
    Hi Paul,

    Popup also one type of page how you insert records into database using page in the same manner you can insert records into database in popup also, there is not much difference using those.

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

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

  • #764862
    just modify this code to suite to your insert. There is no other change specific to extender.

    Regards,
    Asheej T K
    Microsoft MVP[ASP.NET/IIS]
    DotNetSpider MVM

  • #764892
    Hai Paul,
    Popup Extender is just a div on which we show the data which is on the same page.
    So it is just to retrieve the data which is on the same page so you can do the same operations whatever you want.
    The control will be directly attached with the same page so no difficulties in insert/update or delete.
    Just you need to make sure that the parameters are getting correct values:

    cmd.Parameters.AddWithValue("@FirstName", txtfname.Text);
    cmd.Parameters.AddWithValue("@LastName", txtlname.Text);
    cmd.Parameters.AddWithValue("@City", txtCity.Text);
    cmd.Parameters.AddWithValue("@Designation", txtDesg.Text);
    cmd.Parameters.AddWithValue("@UserId", Convert.ToInt32(lblID.Text));

    i suspect the above code parameter values.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764933
    Hi
    Paul try this for Modalpopup update event


    <!-- ModalPopupExtender -->
    <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="btnShow"
    CancelControlID="btnClose" BackgroundCssClass="modalBackground">
    </cc1:ModalPopupExtender>
    <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" style = "display:none">
    This is an ASP.Net AJAX ModalPopupExtender Example<br />
    <asp:Button ID="btnClose" runat="server" Text="Close" />
    <asp:TextBox ID="TxtName" runat="server">
    </asp:TextBox>
    <asp:Button ID="BtnUpdate" runat="server" Text="submit" OnClick="BtnUpdate_Click"/>
    <asp:Label ID="lblError" runat="server" Text=""></asp:Label>
    </asp:Panel>
    <!-- ModalPopupExtender -->



    server side


    protected void BtnUpdate_Click(object sender, EventArgs e)
    {
    lblError.Text = TxtName.Text;
    //put your update method.
    }

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

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

  • #764961
    Thanks for all of your reply to my friends and Brothers ,

    Almost i got exact output.

    if any query let me inform you .

    Thanks with
    Paul.S


Sign In to post your comments