Hi Frndz,
Functionality: Ontexbox Change Event Bind DropDown list trhough DB table
Added one texbox set AutoPostback True and added OnTextChange Event
<asp:TextBox ID="txtCollage" runat="server" OnTextChanged="txtCollage_TextChanged" AutoPostBack="true"></asp:TextBox>
After then based on Collage Textbox value bind Dropdown
myCMD.CommandText = "Select BaranchID, BranchName from Collage where CollageName='" + txtCollage.Text + "'";
Full Logic wtih Textbox and DropDown :
<asp:TextBox ID="txtCollage" runat="server" OnTextChanged="txtCollage_TextChanged" AutoPostBack="true"></asp:TextBox>
<asp:DropDownList ID="ddlBranch" runat="server"></asp:DropDownList>
protected void txtCollage_TextChanged(object sender, EventArgs e)
{
BindBranchDDByCollageName(ddlBranch);
}
public void BindBranchDDByCollageName(DropDownList ddlBranch)
{
SqlConnection con;
SqlCommand myCMD;
SqlDataReader myReader;
try
{
con = new SqlConnection(Convert.ToString(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"]));
con.Open();
myCMD = new SqlCommand();
myCMD.Connection = con;
myCMD.CommandTimeout = 200;
myCMD.CommandText = "Select BaranchID, BranchName from Collage where CollageName='" + txtCollage.Text + "'";
myCMD.CommandType = CommandType.Text;
myReader = myCMD.ExecuteReader();
ddlBranch.DataSource = myReader;
ddlBranch.DataValueField = "BranchID";
v.DataTextField = " BranchName";
ddlBranch.DataBind();
myReader.Close();
con.Close();
}
catch (Exception ex)
{
throw ex;
}
}
Hope this helpful!
Thanks