0

I am struggling to bind a Drop Down List to a Data Source. Please see the code below:

Private _ConString As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _ConString = ConfigurationManager.ConnectionStrings("GeniedbConnection").ConnectionString
        SqlDataSourceNicheDuplicates.ConnectionString = _ConString
        SqlDataSourceCreatedDate.ConnectionString = _ConString
        SqlDataSourceCreatedDate.SelectCommand = "SELECT dateadded distinct convert(varchar,dateadded,103) as dateadded dbNicheDuplicates"
        DDLCreatedDate.DataTextField = "dateadded"
        DDLCreatedDate.DataValueField = "dateadded"
        DDLCreatedDate.DataBind()
end sub

If I run the SQL statement in SQL Studio Manager then many results are returned. What am I doing wrong?

I have spent some time Googling this. For example I looked at this question: Populating an ASP.Net DropDownList using VB.Net coding in code-behind file

2 Answers 2

0

Just adding more info to lincolnk's answer. You need to do this - DDLCreatedDate.DataSource = SqlDataSourceCreatedDate;

SqlDataSourceCreatedDate.SelectCommand = "SELECT dateadded distinct convert(varchar,dateadded,103) as dateadded dbNicheDuplicates"
DDLCreatedDate.DataSource = SqlDataSourceCreatedDate;
DDLCreatedDate.DataTextField = "dateadded"
DDLCreatedDate.DataValueField = "dateadded"
DDLCreatedDate.DataBind()
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but the drop down list is still empty.
@w0051977, are you sure this SQL SELECT dateadded distinct convert(varchar,dateadded,103) as dateadded dbNicheDuplicates is working in management console?
Sorry, my fault. There were two tables: dbNicheDuplicates and dbo.dbNicheDuplicate. dbo.dbNicheDuplicate had no data.
0

You are not setting DataSource.

DDLCreatedDate.DataSource = <results>
DDLCreatedDate.DataBind()

You don't list what type of objects your working with so I'm not sure exactly what the missing statement is.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.