how do correct error 'Expression does not produce a value' for populate a dropdownlist?

how do correct error 'Expression does not produce a value' for populate a dropdownlist?

Compiler Error Message: BC30491: Expression does not produce a value.
Line 43: <asp:DropDownList id=myddl runat="server" DataSource="<%#DataBind()%>" DataTextField="rptL1" DataValueField="rptL1">
Show Detailed Compiler Output:
...
target.DataSource = CType(DataBind(),Object)

my code for aspx.vb  is ...  

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
...
        If Not (Page.IsPostBack) Then
            MyDataBind()
            checkIfLocked()
            BindGrid()
        End If

Sub MyDataBind()
        myComm = New SqlDataAdapter("select rptL1 from rptDDL", MyConn)
        Dim myDS As DataSet = New DataSet
        myComm.Fill(myDS, "ddlscore")
        myddl.DataSource = ds.Tables("ddlscore")
myddl.DataTextField = "rptL1"
        myddl.DataValueField = "rptL1"
        myddl.DataBind()
    End Sub

Sub MyDataGrid_Update(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
...
 Dim myddl As DropDownList
        myddl = E.Item.FindControl("myddl")

my code for aspx is ...

<EditItemTemplate>
<asp:DropDownList id=myddl runat="server" DataSource="<%#DataBind()%>" DataTextField="rptL1" DataValueField="rptL1"</asp:DropDownList>
</EditItemTemplate>
bianchefAsked:
Who is Participating?
 
naveenkohliCommented:
define the variable for DDL in your codebehind file.

here is C# equivalent....

protected DropdownList myddl;
0
 
naveenkohliCommented:
You need to specify a datasource here....

DataSource="<%#DataBind()%>"

Which could be any enumeration (array, DataSet, DataList etc. etc.)
0
 
bianchefAuthor Commented:
this is my code behind datasource...
myddl.DataSource = ds.Tables("ddlscore")

do i write aspx code? as...
DataSource="ddlscore"
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
bianchefAuthor Commented:
If I use...
DataSource="ddlscore"

I get error...
Parser Error Message: The server tag is not well formed.
0
 
naveenkohliCommented:
IF you have defined DataSource in codebehind file then you do not need to do it on page. You can remove that attribute form DDL tag.

myddl.DataSource = ds.Tables("ddlscore")
0
 
bianchefAuthor Commented:
I removed from page...
DataSource="ddlscore"

New error in code behind is...
Object reference not set to an instance of an object
Line 143:        myddl.DataSource = ds.Tables("ddlscore")
0
 
bianchefAuthor Commented:
i translated C#
protected DropdownList myddl;

to vb.net
Protected myddl As DropDownList

and still get error
Object reference not set to an instance of an object
Line 143:        myddl.DataSource = ds.Tables("ddlscore")

i am just trying to create a dropdownlist from a database table for one page column. any ideas on what i am doing wrong?
0
 
bianchefAuthor Commented:
I am closing this question since I am working on new code to create a dropdownlist from a database table for one aspx page column

You can see the new question at http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21832235.html

Although my question was not answered with a solution, I will award 50 points to naveenkohli for giving me some ideas on getting data for a dropdownlist.

Thanks
0
 
bianchefAuthor Commented:
Oops, its 250 points (not 50 points)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.