Hi Bhavesh23,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<table class="mx-auto table-hover table-bordered">
<tr>
<td>First Name</td>
<td>
<asp:TextBox ID="txtfname" runat="server" /></td>
</tr>
<tr>
<td>Middle Name</td>
<td>
<asp:TextBox ID="txtmname" runat="server" /></td>
</tr>
<tr>
<td>Last Name</td>
<td>
<asp:TextBox ID="txtlname" runat="server" AutoPostBack="true" OnTextChanged="txtlname_TextChanged" /></td>
</tr>
</table>
<br />
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">Restricted Person</button>
<div class="modal fade" id="myModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title text-danger mx-auto">Block Person</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<table border="1" class="mx-auto table-hover table-bordered">
<tr>
<td colspan="2" class="text-center">
<asp:Image ID="blockpImage" Height="120px" Width="100px" runat="server" /></td>
</tr>
<tr>
<td>NAME</td>
<td>
<asp:Label ID="lblName" runat="server" Text="Label" Width="250px"></asp:Label></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>
<asp:Label ID="lblAddress" runat="server" Text="Label"></asp:Label></td>
</tr>
<tr>
<td>CITY/VILLAGE</td>
<td>
<asp:Label ID="lblCityorvillage" runat="server" Text="Label"></asp:Label></td>
</tr>
<tr>
<td>TALUKA</td>
<td>
<asp:Label ID="lblTaluka" runat="server" Text="Label"></asp:Label></td>
</tr>
<tr>
<td>DISTRICT</td>
<td>
<asp:Label ID="lblDistrict" runat="server" Text="Label"></asp:Label></td>
</tr>
<tr>
<td>CONTACT NO</td>
<td>
<asp:Label ID="lblContactno" runat="server" Text="Label"></asp:Label></td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous" />
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js"
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
<script type="text/javascript">
function showModal() {
$("#myModal").modal('show');
}
</script>
Namespaces
C#
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Code
C#
public string con { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
this.con = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
}
protected void txtlname_TextChanged(object sender, EventArgs e)
{
string stringname = txtfname.Text + " " + txtmname.Text + " " + txtlname.Text;
using (SqlConnection con = new SqlConnection(this.con))
{
using (SqlCommand cmd = new SqlCommand("Select ContactName,Address,City,Country,Region,Phone From Customers where ContactName LIKE '%" + stringname.Trim().Replace(" ", " ") + "%'", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
lblName.Text = dt.Rows[0]["ContactName"].ToString();
lblAddress.Text = dt.Rows[0]["Address"].ToString();
lblCityorvillage.Text = dt.Rows[0]["City"].ToString();
lblTaluka.Text = dt.Rows[0]["Country"].ToString();
lblDistrict.Text = dt.Rows[0]["Region"].ToString();
lblContactno.Text = dt.Rows[0]["Phone"].ToString();
ScriptManager.RegisterStartupScript(this, this.GetType(), "PopUp", "showModal();", true);
}
}
}
}
}
}
VB.Net
Public Property con As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Me.con = ConfigurationManager.ConnectionStrings("constr").ConnectionString
End Sub
Protected Sub txtlname_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim stringname As String = txtfname.Text & " " + txtmname.Text & " " + txtlname.Text
Using con As SqlConnection = New SqlConnection(Me.con)
Using cmd As SqlCommand = New SqlCommand("Select ContactName,Address,City,Country,Region,Phone From Customers where ContactName LIKE '%" & stringname.Trim().Replace(" ", " ") & "%'", con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dt As DataTable = New DataTable()
sda.Fill(dt)
If dt.Rows.Count > 0 Then
lblName.Text = dt.Rows(0)("ContactName").ToString()
lblAddress.Text = dt.Rows(0)("Address").ToString()
lblCityorvillage.Text = dt.Rows(0)("City").ToString()
lblTaluka.Text = dt.Rows(0)("Country").ToString()
lblDistrict.Text = dt.Rows(0)("Region").ToString()
lblContactno.Text = dt.Rows(0)("Phone").ToString()
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "PopUp", "showModal();", True)
End If
End Using
End Using
End Using
End Using
End Sub
Screenshot