Jump to content

drop down list Sub Page_Load()


lovelyhelp

Recommended Posts

i trying to build a drop down list in my registeration form. my drop downlist is for job title.I have created my database name userlogin and my table t_classification and i have id and u_classification in my table.my script is smtg like this:---------------------------------------------------------------------------Sub Page_Load() If Not IsPostBack Then conUserLogin = New SqlConnection("server=localhost;UID=userlogin;psw=******;database=userLogin") conUserLogin.Open() cmdSelect = New SqlCommand("select u_classification from t_classification", conUserLogin) ddlClassification.DataSource = dtrclassification ddlClassification.DataTextField = "user_classification" ddlClassification.DataBind() dtrclassification.Close() conUserLogin.Close() End If End Sub<asp:DropDownList ID="ddlClassification" runat="server" Width="86px"></asp:DropDownList>---------------------------------------------------------------------------------the problem is there is no item in my dropdown list when i run it.

Link to comment
Share on other sites

the variabel you are using as your datascource is not declared (dtrclassification) and ther is no where in your code that the command gets executed.Did you just leave that piece of code out of your post??? If so please post the entire page thanks.

Link to comment
Share on other sites

the variabel you are using as your datascource is not declared (dtrclassification) and ther is no where in your code that the command gets executed.Did you just leave that piece of code out of your post??? If so please post the entire page thanks.

the whole things go like this<%@ Page Language="VB" AutoEventWireup="false" CodeFile="newUserRegisteration.aspx.vb" Inherits="newUserRegisteration" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.SqlClient" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> Dim conUserLogin As SqlConnection Dim cmdSelect1 As SqlCommand Dim cmdSelect As SqlCommand Dim parmReturnValue As SqlParameter Dim intResult As Integer Dim dtrclassification As SqlDataReader Sub Page_Load() If Not IsPostBack Then Try conUserLogin = New SqlConnection("server=localhost;UID=userlogin;psw=;database=userLogin") conUserLogin.Open() cmdSelect = New SqlCommand("select user_classification from t_classification", conUserLogin) dtrclassification = cmdSelect.ExecuteReader() ddlClassification.DataSource = dtrclassification ddlClassification.DataTextField = "user_classification" ddlClassification.DataValueField = "id" ddlClassification.DataBind() Catch ex As Exception Response.Write(ex.ToString & "<br>") Finally dtrclassification.Close() conUserLogin.Close() End Try End If End Sub ::<asp:DropDownList ID="ddlClassification" runat="server" Width="86px"></asp:DropDownList>::
Link to comment
Share on other sites

  • 3 weeks later...
the variabel you are using as your datascource is not declared (dtrclassification) and ther is no where in your code that the command gets executed.Did you just leave that piece of code out of your post??? If so please post the entire page thanks.

Hello , you are not executed the Sql command , that's why u are not getting value in Combo.Regards,Prashant...
Link to comment
Share on other sites

change this

ddlClassification.DataSource = dtrclassification

to

ddlClassification.DataSource = cmdSelect.ExecuteReader(CommandBehavior.CloseConnection)

see if that makes a difference

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...