0

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

Edited by __avd: wrong forum

2
Contributors
2
Replies
22
Views
4 Years
Discussion Span
Last Post by de Source
1

Wrap your databinding code in page_Load handler,

protected void page_load()
 {
  if(!IsPostBack)
    {
     //databinding code
      }
 }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.