I have a stored procedure called “WEB_SEL_SECURITY_QUESTIONS” in my sql database which returns a table as follows.
SEQURITY_QUESTIONS_KEY, KEYCODE, QUESTION
I need to populate a html selectbox with the list of questions I get from executing the above procedure.
This is what I have tried
String s = ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString();
SqlConnection con = new SqlConnection(s);
con.Open();
SqlDataAdapter myAdepter = new SqlDataAdapter("WEB_SEL_SECURITY_QUESTIONS", con);
myAdepter.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
myAdepter.Fill(ds, "WEB_SEL_SECURITY_QUESTIONS");
String questions = ds.Tables["WEB_SEL_SECURITY_QUESTIONS"].Rows[]["QUESTION"].ToString();
securityQuestion1.DataSource = questions;
securityQuestion1.DataBind();
But this populates the select box with only one record and it generates the list items in such a way that, only one character per list item and only the first record.
You could try:
What your first attempt was doing is just taking that single value from one question and using that as the entire data source. So what you need to aim for is make the whole security questions table the data source, and then give it hints as to what columns to use for value and display (DataTextField, DataValueField).