Hi,
i am making an asp application and in code behind file i am trying to bound drop down list from tbl_teacher in which i concatenate the first and last name by this query
`string sqlStatement = "SELECT teacher_id, fname + lname AS Name FROM tbl_teacher";'
and it is working fine i got the drop down selected text as the names of the teachers and always "1" as the selected value but i want the selected value as the teacher's ID from tbl_teacher i am using following code

 if (dt.Rows.Count > 0)
            {
                ddl_TeacherName.DataSource = dt;
                ddl_TeacherName.DataTextField = "Name";
                ddl_TeacherName.DataValueField = "teacher_id";
                ddl_TeacherName.DataBind();
            }

i dont know where i am lacking. kindly explain me if you can
thanks in advance

Wrap your databinding code in page_Load handler,

protected void page_load()
 {
  if(!IsPostBack)
    {
     //databinding code
      }
 }

Thanks avd it is working now.. thumbs up:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.