data binding in dropdown list
-
hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006
-
hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006
-
hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006
just make sure something: - Why do you put the code of data binding in While loop? - Make sure DataTextField and DataValueFied are correct and the datareader has content... << >>
-
just make sure something: - Why do you put the code of data binding in While loop? - Make sure DataTextField and DataValueFied are correct and the datareader has content... << >>
-
hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006
U are binding ListSelUser.DataTextField = dr.GetString(1); But actually in the ist column of ur data reader there is nothing that is the reason u r ddl is not binding Just replace it with ListSelUser.DataTextField = dr.GetString(0); Remove these two lines of code string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; "I find that the harder I work, the more luck I seem to have."
-
hi, actually i had done some correction in that code but still its not runing on dat perticular page but its runin on another page why this is happening? sam.
if so, the only way you have to debug line by line to see what is not correct... << >>
-
hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006