Hi Bhavesh,
Please refer below Sample.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script type='text/javascript'>
function openModal() {
$('[id*=myModal]').modal('show');
}
</script>
<div class="">
<asp:TextBox ID="txtContactName" placeholder="ContactName" runat="server" AutoPostBack="true" OnTextChanged="txtContactName_TextChanged"></asp:TextBox>
<asp:HiddenField ID="hfIndex" runat="server" />
</div>
<div class="modal fade" id="myModal" role="dialog" 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="0" class="mx-auto ">
<tr>
<td colspan="2" class="text-center"></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 </td>
<td> <asp:Label ID="lblCityorvillage" 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>
<asp:Image BorderStyle="Solid" BorderWidth="1px" Height="120" Width="100" ID="vimagesearch" runat="server" /></td>
</tr>
</table>
</div>
<div class="modal-footer">
<div class="mx-auto">
<asp:Button ID="btnNext" CssClass="btn btn-danger" runat="server" Text="Next" OnClick="btnNext_Click" />
<asp:Button ID="btnBack" CssClass="btn btn-danger" runat="server" Text="Previous" OnClick="btnBack_Click" />
<button type="button" class="btn btn-warning" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Code
C#
protected void txtContactName_TextChanged(object sender, EventArgs e)
{
Session["Data"] = null;
string contactName = txtContactName.Text.Trim();
string selectQuery = "SELECT * FROM Customers WHERE ContactName LIKE '%' + @ContactName + '%'";
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
SqlCommand cmd = new SqlCommand(selectQuery, con);
cmd.Parameters.AddWithValue("@ContactName", contactName);
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();
lblDistrict.Text = dt.Rows[0]["Country"].ToString();
hfIndex.Value = "0";
Session["Data"] = dt;
//code for retrice image from Table 2 for blocked person...
ScriptManager.RegisterStartupScript(this, this.GetType(), "PopUp", "openModal();", true);
}
}
}
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
int index = int.Parse(hfIndex.Value) + 1;
DataTable dt = Session["Data"] as DataTable;
if (index < dt.Rows.Count)
{
lblName.Text = dt.Rows[index]["ContactNAME"].ToString();
lblAddress.Text = dt.Rows[index]["ADDRESS"].ToString();
lblCityorvillage.Text = dt.Rows[index]["CITY"].ToString();
lblDistrict.Text = dt.Rows[index]["Country"].ToString();
hfIndex.Value = index.ToString();
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "PopUp", "openModal();", true);
}
protected void btnBack_Click(object sender, EventArgs e)
{
int index = int.Parse(hfIndex.Value) - 1;
DataTable dt = Session["Data"] as DataTable;
if (index >= 0 && index < dt.Rows.Count)
{
lblName.Text = dt.Rows[index]["ContactNAME"].ToString();
lblAddress.Text = dt.Rows[index]["ADDRESS"].ToString();
lblCityorvillage.Text = dt.Rows[index]["CITY"].ToString();
lblDistrict.Text = dt.Rows[index]["Country"].ToString();
hfIndex.Value = index.ToString();
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "PopUp", "openModal();", true);
}
VB.Net
Protected Sub txtContactName_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Session("Data") = Nothing
Dim contactName As String = txtContactName.Text.Trim()
Dim selectQuery As String = "SELECT * FROM Customers WHERE ContactName LIKE '%' + @ContactName + '%'"
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Dim cmd As SqlCommand = New SqlCommand(selectQuery, con)
cmd.Parameters.AddWithValue("@ContactName", contactName)
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()
lblDistrict.Text = dt.Rows(0)("Country").ToString()
hfIndex.Value = "0"
Session("Data") = dt
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "PopUp", "openModal();", True)
End If
End Using
End Using
End Using
End Sub
Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim index As Integer = Integer.Parse(hfIndex.Value) + 1
Dim dt As DataTable = TryCast(Session("Data"), DataTable)
If index < dt.Rows.Count Then
lblName.Text = dt.Rows(index)("ContactNAME").ToString()
lblAddress.Text = dt.Rows(index)("ADDRESS").ToString()
lblCityorvillage.Text = dt.Rows(index)("CITY").ToString()
lblDistrict.Text = dt.Rows(index)("Country").ToString()
hfIndex.Value = index.ToString()
End If
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "PopUp", "openModal();", True)
End Sub
Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim index As Integer = Integer.Parse(hfIndex.Value) - 1
Dim dt As DataTable = TryCast(Session("Data"), DataTable)
If index >= 0 AndAlso index < dt.Rows.Count Then
lblName.Text = dt.Rows(index)("ContactNAME").ToString()
lblAddress.Text = dt.Rows(index)("ADDRESS").ToString()
lblCityorvillage.Text = dt.Rows(index)("CITY").ToString()
lblDistrict.Text = dt.Rows(index)("Country").ToString()
hfIndex.Value = index.ToString()
End If
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "PopUp", "openModal();", True)
End Sub
Screenshot