We use one link button from which we pop up the grid view control and then inside the grid view whatever you choose will be shown in the other pop-up.
Initial Chamber
Step 1
Open Visual Studio 2010 and create an empty website, provide it a suitable name such as gridview_demo.
Step 2
In Solution Explorer you will get your empty website. Add a web form and SQL Database as in the following.
For Web Form
gridview_demo (your empty website) then right-click and select Add New Item, Web Form. Name it gridview_demo.aspx.
For SQL Server Database
gridview_demo (your empty website) then right-click and select Add New Item, SQL Server Database. (Add the database inside the App_Data_folder).
Database Chamber
Step 3
Get to your database (Database.mdf). We will create a table tbl_Data. Now go to the database.mdf, then Table and Add New table, design your table as in the following:
Table: tbl_data, don't forget to set the ID as Identity Specification - Yes.
Design Chamber
Step 4
Now open your gridview_demo.aspx file, where we create our design for modal pop-up extender.
Gridview_demo.aspx
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
- <!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></title>
- <style type="text/css">
- .style2
- {
- width: 116px;
- }
- .style3
- {
- width: 202px;
- }
- #man
- {
- margin:200px,500px,0px,200px;
- padding:200px,550px,0px,200px;
- }
- .style4
- {
- font-size: large;
- text-align: left;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
- </asp:ToolkitScriptManager>
- <div>
- <asp:ModalPopupExtender ID="ModalPopupExtender1" EnableViewState="true" CancelControlID="Button2" TargetControlID="LinkButton1" PopupControlID="Panel1" runat="server">
- </asp:ModalPopupExtender>
- <div class="man">
- <asp:LinkButton ID="LinkButton1" runat="server"
- style="text-align: center" BackColor="#CCFFFF" ForeColor="#666633">Open your Grid View Here!!</asp:LinkButton>
- </div>
- <asp:LinkButton ID="Linkbtn" runat="server"></asp:LinkButton>
- <asp:ModalPopupExtender ID="ModalPopupExtender2" TargetControlID="Linkbtn" CancelControlID="btnclose" PopupControlID="Panel2" runat="server">
- </asp:ModalPopupExtender>
- <asp:Panel ID="Panel1" runat="server">
- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
- CellPadding="4" onselectedindexchanged="GridView1_SelectedIndexChanged"
- ForeColor="#333333" GridLines="None">
- <AlternatingRowStyle BackColor="White" />
- <Columns>
- <asp:TemplateField HeaderText="id">
- <EditItemTemplate>
- <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("id") %>'></asp:TextBox>
- </EditItemTemplate>
- <ItemTemplate>
- <asp:Label ID="Label1" runat="server" Text='<%# Bind("id") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Name">
- <EditItemTemplate>
- <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("name") %>'></asp:TextBox>
- </EditItemTemplate>
- <ItemTemplate>
- <asp:Label ID="Label2" runat="server" Text='<%# Bind("name") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="City">
- <EditItemTemplate>
- <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("city") %>'></asp:TextBox>
- </EditItemTemplate>
- <ItemTemplate>
- <asp:Label ID="Label3" runat="server" Text='<%# Bind("city") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:ButtonField CommandName="Select" Text="Select" />
- </Columns>
- <FooterStyle BackColor="#990000" ForeColor="White" Font-Bold="True" />
- <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
- <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
- <RowStyle ForeColor="#333333" BackColor="#FFFBD6" />
- <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
- <SortedAscendingCellStyle BackColor="#FDF5AC" />
- <SortedAscendingHeaderStyle BackColor="#4D0000" />
- <SortedDescendingCellStyle BackColor="#FCF6C0" />
- <SortedDescendingHeaderStyle BackColor="#820000" />
- </asp:GridView>
- <br />
- </asp:Panel>
- <asp:Panel ID="Panel2" runat="server">
- <table style="width: 100%;" bgcolor="#FFFFCC" border="1px">
- <caption class="style4">
- <strong> This is your Selected Data</strong></caption>
- <tr>
- <td class="style2">
- <asp:Label ID="Label7" runat="server" Text="ID:"></asp:Label>
- </td>
- <td class="style3">
- <asp:Label ID="Label4" runat="server" ForeColor="#009933" Text="Label"></asp:Label>
- </td>
- </tr>
- <tr>
- <td class="style2">
- <asp:Label ID="Label8" runat="server" Text="Name:"></asp:Label>
- </td>
- <td class="style3">
- <asp:Label ID="Label5" runat="server" Text="Label" ForeColor="#009933"></asp:Label>
- </td>
- </tr>
- <tr>
- <td class="style2">
- <asp:Label ID="Label9" runat="server" Text="City:"></asp:Label>
- </td>
- <td class="style3">
- <asp:Label ID="Label6" runat="server" ForeColor="#009933" Text="Label"></asp:Label>
- </td>
- </tr>
- <tr>
- <td class="style2">
- </td>
- <td class="style3">
- <asp:Button ID="btnclose" runat="server" BackColor="#99CCFF" Text="Close"/>
- </td>
- </tr>
- </table>
- </asp:Panel>
- </div>
- </form>
- </body>
- </html>

Code Chamber
Step 5
Open your gridview_demo.aspx.cs and write some code so that our application works.
Gridview_demo.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Data.SqlClient;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
- SqlCommand cmd = new SqlCommand("select * from tbl_data", con);
- SqlDataAdapter sda = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- sda.Fill(dt);
- GridView1.DataSource = dt;
- GridView1.DataBind();
- }
- }
- protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
- {
- Label4.Text = (GridView1.SelectedRow.FindControl("Label1") as Label).Text;
- Label5.Text = (GridView1.SelectedRow.FindControl("Label2") as Label).Text;
- Label6.Text = (GridView1.SelectedRow.FindControl("Label3") as Label).Text;
- ModalPopupExtender2.Show();
- }
- }



It works like this. When you click on the first link, it will show the GridView in the pop-up. Inside the grid view we took a button field as Select, so when you click on the select button of any ID, it will call another Pop-up where we had shown that specific ID data that you have selected.
Have a good day! Thank you for reading. I hope you liked it.

Arul RPosted Oct 28, 2015, 5:39 AM
Good one !!!
Hamza JavedPosted Jul 9, 2015, 5:50 AM
Nice
Gowtham RajamanickamPosted Jul 7, 2015, 7:00 AM
good one..
Jaipal ReddyPosted Jul 7, 2015, 6:03 AM
Nice
SharadPosted Jul 7, 2015, 12:20 AM
nice article...
Santhakumar MunuswamyPosted Jul 6, 2015, 3:41 PM
Thanks for sharing
Pankaj Kumar ChoudharyPosted Jul 6, 2015, 9:39 AM
Nice and Useful Article Nilesh Sir................
Sibeesh VenuPosted Jul 6, 2015, 9:11 AM
Thanks for sharing :)
Debasis SahaPosted Jul 6, 2015, 8:47 AM
Thanks for sharing..
RakeshPosted Jul 6, 2015, 8:40 AM
Good article bro
Upendra Pratap ShahiPosted Jul 6, 2015, 8:27 AM
again very very nice... Nilesh Jadav