0

I’m getting an error when I try to do something like this below,

<% if (Eval("DescriptionShort") == "")
    { %>
    There is no description for this winery
<%}
    { %>
    <%# Eval("DescriptionShort") %>
<%}%>

The error I’m getting is,

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

Am I able to do something like this? If not can I do something in the code behind with this?

SqlDataAdapter adDetail = new SqlDataAdapter("SELECT * FROM TBLWineries WHERE WineryShow = 'True' AND WineryRegionFK =" + Request["WineryRegionID"], conn);

DataSet dsDetail = new DataSet();
adDetail.Fill(dsDetail);

Edit

It's a DataList with a table inside, I need that for the layout of the page. The next two lines of code show how I populate the DataList,

WineryListDL.DataSource = dsDetail;
WineryListDL.DataBind();

Someone elsewhere said I could use this, it doesn't give an error it doesn't display the else part! if "DescriptionShort" exists it works fine but if not I get no text.

<%# Eval("DescriptionShort") == "" ? "There is no description for this winery" : Eval("DescriptionShort") %>

Should that work, if so, it may be something to do with "DescriptionShort" not being null or ""???

Cheers,

Mike.

1 Answer 1

2

You should do exactly as error said - use some sort of databound control e.g. GridView.
For example bind your dataset to GridView.DataSource property and use Eval function to provide values for cells.

Take a look at this MSDN article Data-Binding Expressions Overview
And this is example how to use GidView and SqlDataAdapter together: How to Edit,Update,Delete in Gridview

Sign up to request clarification or add additional context in comments.

1 Comment

Probably your new problem described here stackoverflow.com/questions/5224264/…

Your Answer

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