coding for dropdownlist

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gody
    New Member
    • Mar 2007
    • 1

    coding for dropdownlist

    hi im new to c# and .net2.0 can anybody plz help ...... i have all the details of empid in dropdown listbox and if i click the empid the date related to that id shoul de displayed...... ... i have attached the code...plz say me the corrections.... .


    Code:
     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
    
            // CODE FOR GETTING THE DATA FROM SQLTABEL
            int employeeid = Convert.ToInt16(DropDownList1.SelectedIndex);
            SqlConnection con = new SqlConnection("Data Source=MS1;Initial Catalog=MSRegSys;uid=sa;Password=ms123");
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select EmpID,EmpCode,lo.LocationName,dp.DepName from usr_tblMs_Employee em INNER JOIN usr_tblMs_Department dp ON dp.DeptID=em.DeptID INNER JOIN usr_tblMs_Location lo ON lo.LocationID=dp.LocationID where em.EmpID=employeeid ", con);
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt=ds.Tables["e"];
            DataRow dr = dt.Rows[0];
            DropDownList1.Text = dr[0].ToString();
            txtempcode.Text = dr[1].ToString();
            txtdept.Text = dr[2].ToString();
            txtlocation.Text = dr[3].ToString();
        }
    Last edited by kenobewan; Mar 19 '07, 10:02 AM. Reason: Add code tags
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    How should the date be displayed? Please explain your requirements clearly and post any errors. Thanks.

    Comment

    • prisesh26
      New Member
      • Sep 2006
      • 29

      #3
      hi,

      one thing is not clear here..
      u cant ve all the details of the employee in dropdownlist.
      u can ve all ids in ddlist.
      if u ve so.. u ve toi write a code inside dropdownlist_ch age()
      here it goes..

      sqldataadapter da = new sqldataadapter( "select date from table where eid= ' " + ddlist.selected item.text.trim + " ' ",con);

      dataset ds= new dataset();
      da.fill(ds,"e")
      u can display the date ... label.text= ds.tables["e"].rows[0][0];
      u ll get the solution..
      try this out

      Comment

      Working...