Jump to content

what is the problem??


Guest hb2

Recommended Posts

i have a questioon..why when i create a DropDownList item in asp.net and bind it to database value then try to display it :Dim DropDownList1 As New DropDownListDim objCmd As New OleDbCommand("SELECT id FROM student", objConn)Dim objD As OleDbDataAdapterobjD = New OleDbDataAdapter(objCmd)Dim data As New DataSetobjD.Fill(data, "student")DropDownList1.DataSource = dataDropDownList1.DataBind()Response.Write(DropDownList1)the final result in the screen is not the dropdownlist but:System.Web.UI.WebControls.DropDownList so what is the problem??

Link to comment
Share on other sites

hi hb2... you must specify value for the datagrid.datvalue and datagrid.datatext (im not sure abt the syntax though) ... DropDownList1.DataSource = data DropDownList1.DataValue = column name DropDownList1.DataText = column name DropDownList1.DataBind()

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

You can't just use Response.Write. That is for writing text but DropDownList1 is an object.You have to add it to the Page COntrols.Dim DropDownList1 As New DropDownListDim objCmd As New OleDbCommand("SELECT id FROM student", objConn)Dim objD As OleDbDataAdapterobjD = New OleDbDataAdapter(objCmd)Dim data As New DataSetobjD.Fill(data, "student")DropDownList1.DataSource = dataDropDownList1.DataBind()Controls.Add(DropDownList1) 'Use this line to add it to the page

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...