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

    Modal popup with gridview

    In my First Page i have a text box and button.

    When i click button a new pop with grid view data should open.

    After selecting the row in grid view the selected row value should be display in text box and modal should be closed.

    I can open the grid view with data but can't able to close and get the value to my text box.

    Please help needed.


    Code for opening popup:

    <asp:Button ID="Button1" runat="server" Text="Fill Form in Popup" OnClick="Button1_Click" />

    <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1"
    CancelControlID="Button2" BackgroundCssClass="Background">
    <asp:Panel ID="Panl1" runat="server" CssClass="Popup" style = "display:none">
    <iframe style=" width: 350px; height: 300px;" id="irm1" src="GridViewTest.aspx" runat="server"></iframe>
    <asp:Button ID="Button2" runat="server" Text="Close" />

    <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
  • #761547

    What do you want exactly.?

    What you are expecting from our end.?

    Please elaborate then only we can provide some what better solution to resolve the issue.

    Hope this will helpful to you...

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

    Blog :

  • #761548
    Sorry i missed some part of question and now attached it.

    Thanks for response

  • #761556

    As per description, you got data in textbox while edit the gridview row but the problem is closing modal dialog right.?

    In that case use below sample code to hide modalpopupextender control.


    using Hide method modalpopextender control hide.

    Hope this will helpful to you..

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

    Blog :

  • #761558
    I am not getting the text value of popup window to to my first page textbox.

  • #761593

    Hello Syed Thahir Hussain,

    Refer the below code :

    HTML Mark up :

    <html xmlns="">
    <head runat="server">
    <style type ="text/css">
    filter: alpha(opacity=60);
    opacity: 0.6;

    border: 1px solid #4C3C1B;
    padding: 5px;
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    Name : <asp:TextBox ID="TextBoxName" runat="server" Enabled="False"></asp:TextBox><br />
    Class :  <asp:TextBox ID="TextBoxClass" runat="server" Enabled="False"></asp:TextBox><br /><br />

    <asp:Button ID="ButtonShowDialog" runat="server" Text="Show Dialog" ToolTip="Show student details"/>
    <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="ButtonShowDialog" BackgroundCssClass="modalBackground" Enabled="true" PopupControlID="Panel1" Drag="false"></cc1:ModalPopupExtender>
    <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333">
    <AlternatingRowStyle BackColor="White" />
    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Select</asp:LinkButton>
    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
    <asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
    <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
    <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
    <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
    <SortedAscendingCellStyle BackColor="#FDF5AC" />
    <SortedAscendingHeaderStyle BackColor="#4D0000" />
    <SortedDescendingCellStyle BackColor="#FCF6C0" />
    <SortedDescendingHeaderStyle BackColor="#820000" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [StudentDetails]"></asp:SqlDataSource>
    <br />
    <asp:Button ID="ButtonClose" runat="server" Text="Close" OnClick="ButtonClose_Click"/>

    Code - Behind :

    private void closepopup()
    protected void Page_Load(object sender, EventArgs e)
    TextBoxName.Text = null;
    TextBoxClass.Text = null;

    protected void LinkButton1_Click(object sender, EventArgs e)
    GridViewRow gvRow = (GridViewRow)(sender as Control).Parent.Parent;
    int index = gvRow.RowIndex;

    TextBoxName.Text = GridView1.Rows[index].Cells[1].Text;
    TextBoxClass.Text = GridView1.Rows[index].Cells[2].Text;

    protected void ButtonClose_Click(object sender, EventArgs e)

    See the attached file.
    It's sample project of this code.

    Hope this will help you.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


    Delete Attachment

  • #761594
    Hello Syed Thahir Hussain,

    See the attached file. It's an output of above code.

    Hope this will help you and it is as per your requirement.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #761799
    Thanks man it works.

  • Sign In to post your comments