[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-04-28
10
Medium Priority
?
3,444 Views
Last Modified: 2012-06-27
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>
0
Comment
Question by:bianchef
  • 7
  • 3
10 Comments
 
LVL 23

Expert Comment

by:naveenkohli
ID: 16567026
You need to specify a datasource here....

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

Which could be any enumeration (array, DataSet, DataList etc. etc.)
0
 

Author Comment

by:bianchef
ID: 16567045
this is my code behind datasource...
myddl.DataSource = ds.Tables("ddlscore")

do i write aspx code? as...
DataSource="ddlscore"
0
 

Author Comment

by:bianchef
ID: 16567053
If I use...
DataSource="ddlscore"

I get error...
Parser Error Message: The server tag is not well formed.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:naveenkohli
ID: 16567061
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
 

Author Comment

by:bianchef
ID: 16567086
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
 
LVL 23

Accepted Solution

by:
naveenkohli earned 750 total points
ID: 16567105
define the variable for DDL in your codebehind file.

here is C# equivalent....

protected DropdownList myddl;
0
 

Author Comment

by:bianchef
ID: 16567125
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
 

Author Comment

by:bianchef
ID: 16569544
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
 

Author Comment

by:bianchef
ID: 16569553
Oops, its 250 points (not 50 points)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question