Hi SUJAYS,
Please refer below sample.
HTML
<asp:TextBox ID="txtId" runat="server" AutoPostBack="true" OnTextChanged="BindDropdown"></asp:TextBox>
<asp:DropDownList ID="ddlCountry" runat="server">
</asp:DropDownList>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Code
C#
BEL.cs
public class BEL
{
private int _Id;
public int id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
}
BLL.cs
public class BLL
{
public DataTable GetData(BEL enities)
{
DAL dal = new DAL();
return dal.Data(enities);
}
}
DAL.cs
public DataTable Data(BEL enities)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Country FROM Customers WHERE CustomerId = @Id", con))
{
cmd.Parameters.AddWithValue("@Id", enities.id);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
}
}
CS.aspx.cs
protected void BindDropdown(object sender, EventArgs e)
{
BEL entity = new BEL();
entity.id = Convert.ToInt32(txtId.Text);
BLL bll = new BLL();
DataTable dt = bll.GetData(entity);
ddlCountry.DataSource = dt;
ddlCountry.DataTextField = "Country";
ddlCountry.DataValueField = "Country";
ddlCountry.DataBind();
}
VB.Net
BELVB.vb
Private _Id As Integer
Public Property id As Integer
Get
Return _Id
End Get
Set(ByVal value As Integer)
_Id = value
End Set
End Property
BLLVB.vb
Public Function GetData(ByVal enities As BELVB) As DataTable
Dim dal As DALVB = New DALVB()
Return dal.Data(enities)
End Function
DALVB.vb
Public Function Data(ByVal enities As BELVB) As DataTable
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT Country FROM Customers WHERE CustomerId = @Id", con)
cmd.Parameters.AddWithValue("@Id", enities.id)
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
Return dt
End Using
End Using
End Using
End Function
VB.aspx.vb
Protected Sub BindDropdown(ByVal sender As Object, ByVal e As EventArgs)
Dim entity As BELVB = New BELVB()
entity.id = Convert.ToInt32(txtId.Text)
Dim bll As BLLVB = New BLLVB()
Dim dt As DataTable = bll.GetData(entity)
ddlCountry.DataSource = dt
ddlCountry.DataTextField = "Country"
ddlCountry.DataValueField = "Country"
ddlCountry.DataBind()
End Sub
Screenshot