bianchef
asked on
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"</as p:DropDown List>
</EditItemTemplate>
Compiler Error Message: BC30491: Expression does not produce a value.
Line 43: <asp:DropDownList id=myddl runat="server" DataSource="<%#DataBind()%
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()%
</EditItemTemplate>
ASKER
this is my code behind datasource...
myddl.DataSource = ds.Tables("ddlscore")
do i write aspx code? as...
DataSource="ddlscore"
myddl.DataSource = ds.Tables("ddlscore")
do i write aspx code? as...
DataSource="ddlscore"
ASKER
If I use...
DataSource="ddlscore"
I get error...
Parser Error Message: The server tag is not well formed.
DataSource="ddlscore"
I get error...
Parser Error Message: The server tag is not well formed.
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")
myddl.DataSource = ds.Tables("ddlscore")
ASKER
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")
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")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
ASKER
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 https://www.experts-exchange.com/questions/21832235/how-do-I-correct-a-datavaluefield-error-for-populating-a-dropdownlist-from-a-database.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
You can see the new question at https://www.experts-exchange.com/questions/21832235/how-do-I-correct-a-datavaluefield-error-for-populating-a-dropdownlist-from-a-database.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
ASKER
Oops, its 250 points (not 50 points)
DataSource="<%#DataBind()%
Which could be any enumeration (array, DataSet, DataList etc. etc.)