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

    Gridview Button Click Popup Window

    In Gridview field inside it have image button .click image button to show popup window with textbox.I have entered text and click ok the popwindow is close and textbox value have i want to save.If again i click image button last i have entered text value will be show on popup window.How to do this.
  • #725517
    Hi,

    Refer below code sample as per your requirement
    .aspx

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>AJAX POP UP</title>
    <style type="text/css">
    .modalBackground
    {
    background-color: Gray;
    filter:alpha(opacity=70);
    opacity:0.7;
    }

    .modalPopup
    {
    background-color:#ffffdd;
    border-width:3px;
    border-style:solid;
    border-color:Gray;
    padding:3px;
    width:250px;
    }
    </style>

    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </cc1:ToolkitScriptManager>
    <asp:GridView ID="GridView1" runat="server" DataKeyNames="eno"
    AutoGenerateColumns="false" onrowcommand="GridView1_RowCommand">
    <Columns>
    <asp:TemplateField HeaderText="Employee no">
    <itemtemplate>
    <asp:LinkButton CommandName="cmdBind" runat="server" Text='<%#Eval("eno")%>' ID="hypeno" ToolTip='<%#Eval("eno")%>'>LinkButton
    </asp:LinkButton>
    </itemtemplate>
    </asp:TemplateField>
    <asp:BoundField HeaderText="Employee Name" DataField="empname" />
    <asp:BoundField HeaderText="Employee Salary" DataField="sal" />
    </Columns>
    </asp:GridView><br />

    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Button1" PopupControlID="PnlModal" BackgroundCssClass="modalBackground">
    </cc1:ModalPopupExtender>
    <asp:Button ID="Button1" runat="server" Text="Button" style="visibility:hidden"/>
    <asp:Panel ID="PnlModal" runat="server" Width="500px" CssClass="modalPopup">
    Enter Employee No: <asp:TextBox ID="TextBox1" runat="server" TabIndex="1" Enabled="true"></asp:TextBox><br/>
    Enter Name <asp:TextBox ID="TextBox2" runat="server" TabIndex="2"></asp:TextBox><br/>
    Enter Salary <asp:TextBox ID="TextBox3" runat="server" TabIndex="1"></asp:TextBox><br/><br />
    <asp:Button ID="Button3" runat="server" Text="Update" style="height: 26px" /> <asp:Button ID="Button2" runat="server" Text="cancel" />
    </asp:Panel>

    </div>
    </form>
    </body>
    </html>



    Code behind

    using System.Data;
    using System.Data.SqlClient;
    partial class _Default : System.Web.UI.Page
    {
    SqlConnection sqlcon = new SqlConnection("server=RAVI\\SQLEXPRESS;database=test;uid=ravindran;pwd=srirangam;");
    SqlCommand sqlcmd = new SqlCommand();
    SqlDataAdapter da = new SqlDataAdapter();
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, System.EventArgs e)
    {
    if (!Page.IsPostBack) {
    LoadGrid();
    }
    }
    protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
    if (e.CommandName == "cmdBind") {
    LinkButton lb = (LinkButton)e.CommandSource;
    ModalPopupExtender1.Show();
    getData(lb.Text);
    }
    }
    public void getData(string eno)
    {
    sqlcon.Open();
    sqlcmd = new SqlCommand("select * from emp where eno='" + eno + "'", sqlcon);
    da = new SqlDataAdapter(sqlcmd);
    da.Fill(dt);
    if (dt.Rows.Count > 0) {
    TextBox1.Text = dt.Rows(0)(0).ToString;
    TextBox2.Text = dt.Rows(0)(1).ToString;
    TextBox3.Text = dt.Rows(0)(2).ToString;
    }
    sqlcon.Close();
    }

    protected void Button3_Click(object sender, System.EventArgs e)
    {
    sqlcon.Open();
    sqlcmd = new SqlCommand("update emp set empname='" + TextBox2.Text + "',sal='" + TextBox3.Text + "' where eno='" + TextBox1.Text + "'", sqlcon);
    sqlcmd.CommandType = CommandType.Text;
    sqlcmd.ExecuteNonQuery();
    sqlcon.Close();
    ModalPopupExtender1.Hide();
    LoadGrid();
    }

    protected void Button2_Click(object sender, System.EventArgs e)
    {
    ModalPopupExtender1.Hide();
    }
    public void LoadGrid()
    {
    sqlcon.Open();
    sqlcmd = new SqlCommand("select * from emp", sqlcon);
    da = new SqlDataAdapter(sqlcmd);
    da.Fill(dt);
    if (dt.Rows.Count > 0) {
    GridView1.DataSource = dt;
    GridView1.DataBind();
    }
    sqlcon.Close();
    }
    }

    Regards
    N.Ravindran
    Your Hard work never fails

  • #725526
    Well it seems your code is ready . You have to do nothing . when you click image . Your pop comes rt. Then when you close or click save .you sabe the value some where in db.So after data is inserted. Set the text1.text="";
    if need a simply way doing this. so every time pages complete the execution set textbox as null..

    Regards
    Rakesh Chaubey
    rakeshchaubey1989@gmail.com


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.