Click here to Skip to main content
15,886,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have dropdown list i select value from dropdown list when i select consultant name from dropdownlist i want to show email id of that consultant in listbox.how is this possible?
i write this code but it gives error
C#
protected void  DDConsultantName_SelectedIndexChanged(object sender, EventArgs e)
   {
       SqlConnection cn = new SqlConnection();
       cn.ConnectionString = ConfigurationManager.ConnectionStrings["Homeconstr"].ConnectionString;
       cn.Open();
       SqlCommand command = new SqlCommand("select ContactPerson_EmailID from Consultant_Detail where Consultant_Name=" + this.DDConsultantName.SelectedValue, cn);
       SqlDataAdapter dataAadpter = new SqlDataAdapter(command);
       DataSet ds = new DataSet();
       dataAadpter.Fill(ds);
       LBEmailId.DataSource = ds;
       LBEmailId.DataTextField = "ContactPerson_EmailID";
       //LBEmailId.DataValueField = "Id";
       LBEmailId.DataBind();
       }


when i select e.g morphees consultant from dropdown i want to show his email id in LBemail id listbox ?????????
Posted
Updated 2-Oct-12 20:43pm
v2
Comments
Mohd. Mukhtar 3-Oct-12 3:16am    
What error exactly you are getting??
AshishChaudha 3-Oct-12 4:45am    
have you checked dataset..are you getting the email ID of the selected value??

1 solution

Try this:
C#
protected void  DDConsultantName_SelectedIndexChanged(object sender, EventArgs e)
{
    SqlConnection cn = new SqlConnection();
    cn.ConnectionString = ConfigurationManager.ConnectionStrings["Homeconstr"].ConnectionString;
    cn.Open();
    SqlCommand command = new SqlCommand("select ContactPerson_EmailID from Consultant_Detail where Consultant_Name='" + this.DDConsultantName.SelectedValue + "'", cn);
    SqlDataAdapter dataAadpter = new SqlDataAdapter(command);
    DataSet ds = new DataSet();
    dataAadpter.Fill(ds);
    if(ds != null){
        LBEmailId.DataSource = ds.Tables[0];
        LBEmailId.DataTextField = "ContactPerson_EmailID";
        //LBEmailId.DataValueField = "Id";
        LBEmailId.DataBind();
    }
}



Hope it helps!
--Amit
 
Share this answer
 
Comments
16041984 3-Oct-12 3:20am    
when i use this it is running but not showing any result in listboxemailid i.e LBEmailID.pls help
ujju.1 3-Oct-12 3:31am    
have you set AutoPostBack="True" for DDConsultantName?
16041984 3-Oct-12 3:45am    
yes i set autopostback = true for dropdown
<asp:DropDownList ID="DDConsultantName" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDConsultantName_SelectedIndexChanged">

it shows
Mohd. Mukhtar 3-Oct-12 4:05am    
put break point and check if anything is coming in ds.Tables[0];
16041984 3-Oct-12 4:59am    
i will do one thing i take one textbox then add email id's in listbox ....problem solved....thank u for ur reply all of u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900