Hi indradeo,
Please refer below sample code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<div>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×</button>
<h4 class="modal-title">Requst Details</h4>
</div>
<div class="modal-body">
<div class="col-lg-12 col-sm-12 col-md-12 col-xs-12">
<div class="form-group">
<font size='2'>
<b>ID :</b> <asp:Label ID="Id" runat="server" Text="Id"></asp:Label> <br /><br />
<b>Employee Id : </b><asp:Label ID="EmpCode" runat="server" Text="EmpCode"></asp:Label>
</font>
</div>
<font size='2'>
<div class="form-group">
<b>Asset Type : </b> <asp:Label ID="asst_typ" runat="server" Text=""></asp:Label>
</div>
</font>
</div>
<font size='2'>
<div class="form-group">
<b>Location : </b><asp:Label ID="lcn" runat="server" Text="lcn"></asp:Label> ,
<b>Purpose : </b><asp:Label ID="prps" runat="server" Text="prps"></asp:Label><br /><br />
<b>Remark : </b><asp:Label ID="rmk" runat="server" Text="rmk"></asp:Label>
</div>
</font>
<font size='2'>
<div class="form-group">
<b>Asset Status : <asp:dropdownlist id="ddlTest" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList_Changed" >
<asp:ListItem Text="--Select Country --" Value="C" />
<asp:ListItem Text="USA" Value="USA" />
<asp:ListItem Text="UK" Value="UK" />
</asp:dropdownlist>
<b>Intalation date : </b><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</b><br /><br />
<b>Asset Serial No. : </b><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br /><br />
<b>Remark : </b><asp:TextBox ID="TextBox1" runat="server" width="300px"></asp:TextBox>
</div>
</font>
</div>
<div class="modal-footer">
<asp:Button ID="btnSave" runat="server" Text="Save" ToolTip='Click here to Save Data' CssClass="btn btn-info" />
<asp:Button ID="btnchk" runat="server" Text="Send" ToolTip='Click here to Check Asset Details' CssClass="btn btn-info" />
<button type="button" class="btn btn-info" data-dismiss="modal">
Close</button>
</div>
</div>
</div>
</div>
<script type='text/javascript'>
function openModal() {
$('[id*=myModal]').modal('show');
}
</script>
</div>
Namespace
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "openModal();", true);
}
}
protected void DropDownList_Changed(object sender, EventArgs e)
{
TextBox1.Visible = false;
TextBox2.Visible = false;
TextBox3.Visible = false;
if (ddlTest.SelectedItem.Value == "USA" || ddlTest.SelectedItem.Value == "UK")
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = "SELECT * FROM Employees WHERE Country = @Country";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("@Country", ddlTest.SelectedItem.Value);
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
TextBox1.Text = dt.Rows[0]["Notes"].ToString();
TextBox2.Text = Convert.ToDateTime(dt.Rows[0]["BirthDate"]).ToShortDateString();
TextBox3.Text = dt.Rows[0]["EmployeeId"].ToString();
TextBox1.Visible = true;
TextBox2.Visible = true;
TextBox3.Visible = true;
}
}
}
}
}
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "openModal();", true);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
ClientScript.RegisterStartupScript(Me.GetType(), "Popup", "openModal();", True)
End If
End Sub
Protected Sub DropDownList_Changed(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
TextBox1.Visible = False
TextBox2.Visible = False
TextBox3.Visible = False
If ddlTest.SelectedItem.Value = "USA" OrElse ddlTest.SelectedItem.Value = "UK" Then
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim query As String = "SELECT * FROM Employees WHERE Country = @Country"
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand(query, con)
cmd.Parameters.AddWithValue("@Country", ddlTest.SelectedItem.Value)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dt As DataTable = New DataTable()
sda.Fill(dt)
TextBox1.Text = dt.Rows(0)("Notes").ToString()
TextBox2.Text = Convert.ToDateTime(dt.Rows(0)("BirthDate")).ToShortDateString()
TextBox3.Text = dt.Rows(0)("EmployeeId").ToString()
TextBox1.Visible = True
TextBox2.Visible = True
TextBox3.Visible = True
End Using
End Using
End Using
End Using
End If
ClientScript.RegisterStartupScript(Me.GetType(), "Popup", "openModal();", True)
End Sub
Screenshot