Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
this my code for creating the Service:


C#
public  String GetEmployeerid()
      {

          string strConnection = ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
          SqlConnection conn = new SqlConnection(strConnection);
          SqlCommand cmd = new SqlCommand("Select Employeerid from Employeertable", conn);
          conn.Open();
          //cmd.ExecuteNonQuery();
          SqlDataAdapter da = new SqlDataAdapter(cmd);
          DataSet ds = new DataSet();
          da.Fill(ds);
          return "";

      }


This is the code for get the employeer id, which is going to be selected from drop down:

C#
protected void Page_Load(object sender, EventArgs e)
{

    objService = new ServiceReference1.Service1Client();
    DropDownList1.DataSource = objService.GetEmployeerid();
    DropDownList1.DataBind();

}




but after debugging i m getting empty dropdown the items are hidden. how to proceed please suggest.
Posted
Updated 7-Jan-13 20:59pm
v2

You will have to let the dropdownlist know what should be used to display as text and what should be the value of each item. to do that do the following before databind.

C#
DropDownList1.DataTextField="Employeerid" ;
DropDownList1.DataValueField="Employeerid" ;
 
Share this answer
 
Comments
Dhritirao's 8-Jan-13 4:26am    
i tried still i m not getting
Rahul Rajat Singh 8-Jan-13 5:12am    
Found the possible bug in your code. Check out my other solution. You will have to use both the solutions to get the results.
You also need to change this function:
C#
public  DataTable GetEmployeerid()
        {
 
            string strConnection = ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
            SqlConnection conn = new SqlConnection(strConnection);
            SqlCommand cmd = new SqlCommand("Select Employeerid from Employeertable", conn);
            conn.Open();
            //cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt; 
        }
 
Share this answer
 
write this before databind method
C#
DropDownList1.DataTextField=Employeerid ;
DropDownList1.DataValueField=Employeerid ;
 
Share this answer
 
v2
Comments
Rahul Rajat Singh 8-Jan-13 3:02am    
The EmployeerID should be a string literal i.e. "EmployeerID"
Dhritirao's 8-Jan-13 4:24am    
ya its a string

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