Hi AnkitPal,
Check this example. Now please take its reference and correct your code.
HTML
First Page
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div class="row">
<div class="col-12">
<span style="font-size: small;">Enter Supplier Name :</span>
</div>
<div class="col-12" style="width: 100%;">
<asp:TextBox ID="TextBox1" runat="server" CssClass="textBox_BottomLine" Font-Bold="true" Font-Size="20px" Style="text-transform: uppercase;"></asp:TextBox>
<asp:Button ID="btnOpenPopupWindowGet" runat="server" Text="Get" OnClick="btnOpenPopupWindowGet_Click" />
<asp:Button ID="Button5" runat="server" Text="Verify" />
<br />
<asp:Label ID="Label8" runat="server" Text="Action Required" Font-Size="Small"></asp:Label>
<asp:Label ID="lblVendorId" runat="server" Font-Size="Smaller" Visible="false"></asp:Label>
</div>
</div>
<table>
<tr>
<td>Vendor Id</td>
<td>
<asp:TextBox ID="txtVendorId" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Vendor Name</td>
<td>
<asp:TextBox ID="txtVendorName" runat="server"></asp:TextBox></td>
</tr>
</table>
</asp:Content>
Second Page
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<fieldset>
<legend>Search Vendor/Supplier Name</legend>
<div class="row">
<div class="col-12">
<div class="row" style="background-color: #eee; border-radius: 5px; border-top: 3px solid #666699;">
<div class="col-3">Enter Supplier Name :</div>
<div class="col-8">
<asp:TextBox ID="TextBox1" runat="server" CssClass="textBox_BottomLine" Font-Bold="true" Font-Size="18px"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
</div>
</div>
</div>
<div class="row">
<asp:Panel ID="Panel1" runat="server" Style="text-align: center;">
<div class="col-12" style="background-color: #eee; border-radius: 5px; border-top: 3px solid Orange; text-align: center; margin-top: 4px; padding: 8px 13px; width: 97%;">
<asp:GridView ID="gv_SearchedVendor" runat="server" AutoGenerateColumns="False" HeaderStyle-BackColor="Orange"
HeaderStyle-Font-Bold="true" ShowHeaderWhenEmpty="True">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkRow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="SN" DataField="RowNo" />
<asp:TemplateField HeaderText="Vendor Id">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("VendorId") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblVendeorId" runat="server" Text='<%# Bind("VendorId") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Vendor Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("VendorName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblVendorName" runat="server" Text='<%# Bind("VendorName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="Orange" Font-Bold="True" />
</asp:GridView>
</div>
<div class="col-12" style="text-align: center;">
<asp:Button ID="btnSelect" runat="server" Text="Select" OnClientClick="SetData()" />
</div>
</asp:Panel>
</div>
</div>
</fieldset>
<script type="text/javascript">
function SetData() {
if (window.opener != null && !window.opener.closed) {
var txtVendorId = window.opener.document.getElementById("ContentPlaceHolder1_txtVendorId");
var txtVendorName = window.opener.document.getElementById("ContentPlaceHolder1_txtVendorName");
var grid = document.getElementById("<%=gv_SearchedVendor.ClientID%>");
var checkBoxes = grid.getElementsByTagName("INPUT");
for (var i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].type == "checkbox") {
if (checkBoxes[i].checked) {
var row = checkBoxes[i].parentNode.parentNode;
txtVendorId.value = row.getElementsByTagName('SPAN')[0].innerHTML;
txtVendorName.value = row.getElementsByTagName('SPAN')[1].innerHTML;
window.close();
return true;
}
}
}
}
}
</script>
</asp:Content>
Code
C#
First Page
protected void btnOpenPopupWindowGet_Click(object sender, EventArgs e)
{
int intId = 100;
string strPopup = "<script language='javascript' ID='script1'>"
+ "window.open('SecondPage.aspx?data=" + HttpUtility.UrlEncode(intId.ToString())
+ "','new window', 'top=90, left=200, width=550, height=350, dependant=no, location=0, alwaysRaised=no, menubar=no, resizeable=no, scrollbars=n, toolbar=no, status=no, center=yes')"
+ "</script>";
ScriptManager.RegisterStartupScript((Page)HttpContext.Current.Handler, typeof(Page), "Script1", strPopup, false);
}
Second Page
protected void btnSearch_Click(object sender, System.EventArgs e)
{
//select VendorId, VendorName from inventory_vendor where VendorName like '%{0}%'
string Query =string.Format( "select VendorId, VendorName from inventory_vendor where VendorName like '%{0}%'", TextBox1.Text.Trim());
DataTable dt = new DataTable();
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
{
SqlCommand command = new SqlCommand(Query, connection);
connection.Open();
using (SqlDataAdapter a = new SqlDataAdapter(command))
{
DataColumn Col = dt.Columns.Add("RowNo", typeof(int));
Col.SetOrdinal(0);
dt.Columns["RowNo"].AutoIncrement = true;
dt.Columns["RowNo"].AutoIncrementSeed = 1;
dt.Columns["RowNo"].AutoIncrementStep = 1;
a.Fill(dt);
}
connection.Close();
}
gv_SearchedVendor.DataSource = dt;
gv_SearchedVendor.DataBind();
}
VB.Net
First Page
Protected Sub btnOpenPopupWindowGet_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim intId As Integer = 100
Dim strPopup As String = "<script language='javascript' ID='script1'>" & "window.open('SecondPage.aspx?data=" & HttpUtility.UrlEncode(intId.ToString()) & "','new window', 'top=90, left=200, width=550, height=350, dependant=no, location=0, alwaysRaised=no, menubar=no, resizeable=no, scrollbars=n, toolbar=no, status=no, center=yes')" & "</script>"
ScriptManager.RegisterStartupScript(CType(HttpContext.Current.Handler, Page), GetType(Page), "Script1", strPopup, False)
End Sub
Second Page
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Query As String = String.Format("select VendorId, VendorName from inventory_vendor where VendorName like '%{0}%'", TextBox1.Text.Trim())
Dim dt As DataTable = New DataTable()
Using connection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Dim command As SqlCommand = New SqlCommand(Query, connection)
connection.Open()
Using a As SqlDataAdapter = New SqlDataAdapter(command)
Dim Col As DataColumn = dt.Columns.Add("RowNo", GetType(Integer))
Col.SetOrdinal(0)
dt.Columns("RowNo").AutoIncrement = True
dt.Columns("RowNo").AutoIncrementSeed = 1
dt.Columns("RowNo").AutoIncrementStep = 1
a.Fill(dt)
End Using
connection.Close()
End Using
gv_SearchedVendor.DataSource = dt
gv_SearchedVendor.DataBind()
End Sub